Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function AddtoLibrary(ByVal UserName As String, ByVal Password As String, ByVal BookIDs As String, ByVal Device As String, ByVal Log As String) As String
- 'Logging
- If Log <> "Internal Silent" Then
- Dim st As StackTrace = New StackTrace()
- Dim sf As StackFrame = st.GetFrame(0)
- Dim currentMethodName As MethodBase = sf.GetMethod()
- Logging(Log, Device, UserName, currentMethodName.Name)
- End If
- 'Database Connection Variables
- Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("CnnStr").ConnectionString
- Dim Cnn As New SqlClient.SqlConnection
- Dim Comm As New SqlClient.SqlCommand
- Dim DA As SqlClient.SqlDataAdapter
- Dim DS As DataSet
- Dim Trans As Data.SqlClient.SqlTransaction
- If Trim(UserName) = "" Or Trim(Password) = "" Or Trim(BookIDs) = "" Or Trim(Device) = "" Or Trim(Log) = "" Then
- Return Nothing
- End If
- Try
- If Cnn.State = ConnectionState.Open Then Cnn.Close()
- Cnn.ConnectionString = ConnectionString
- Cnn.Open()
- DS = New DataSet()
- DA = New SqlClient.SqlDataAdapter("SELECT ID From Users WHERE UserName = '" & Replace(UserName, "'", "") & "' AND Password = '" & Password & "'", Cnn)
- DA.Fill(DS, "Table")
- If DS.Tables("Table").Rows.Count <> 0 Then
- Dim UserID As Integer = DS.Tables("Table").Rows(0).Item("ID")
- If Device = "-1" Then
- Return "DEVICE"
- End If
- Trans = Cnn.BeginTransaction(IsolationLevel.ReadCommitted)
- For i = 0 To BookIDs.Split(";").GetUpperBound(0) - 1
- If Mid(BookIDs.Split(";").GetValue(i).ToString, 1, 2) <> "SB" Then
- DS = New DataSet()
- DA = New SqlClient.SqlDataAdapter("SELECT Price,Discount From Books WHERE ID = " & BookIDs.Split(";").GetValue(i).ToString, Cnn)
- DA.Fill(DS, "Table") // <<<<<<<<<<< HERE I GOT THE EXCEPTION
- If DS.Tables("Table").Rows.Count <> 0 Then
- If DS.Tables("Table").Rows(0).Item("Price") = 0 Or DS.Tables("Table").Rows(0).Item("Discount") = 100 Then
- Comm = New SqlClient.SqlCommand("INSERT INTO Invoices (ID,BookID,UserID,Price,OurShare,PublisherShare,Discount,DiscountType,PaymentDate,PaymentTime,SaleOrderID,SaleReferenceID) VALUES (" & Gen_InvoiceID() & "," & BookIDs.Split(";").GetValue(i).ToString & "," & UserID & ",0,0,0,0,''," & Get_Shamsi() & ",'" & Get_Time() & "','" & 0 & "','" & 0 & "')", Cnn, Trans)
- Comm.ExecuteNonQuery()
- End If
- End If
- Dim BookID As Integer = BookIDs.Split(";").GetValue(i).ToString
- Dim TotalDownload As Integer = 0
- DS = New DataSet()
- DA = New SqlClient.SqlDataAdapter("SELECT DownloadDeviceNumbers FROM Books WHERE ID = " & BookID, Cnn)
- DA.Fill(DS, "Table")
- If DS.Tables("Table").Rows.Count <> 0 Then
- TotalDownload = DS.Tables("Table").Rows(0).Item("DownloadDeviceNumbers")
- Else
- Return Nothing
- End If
- Dim DS1 As New DataSet()
- Dim DA1 As New SqlClient.SqlDataAdapter("SELECT DISTINCT([DeviceID]) FROM [ketabchinDB].[dbo].[UserActivations] WHERE BookID = " & BookID & " AND UserID = " & UserID & " AND DeviceID = '" & Device & "'", Cnn)
- DA1.Fill(DS1, "Table")
- If DS1.Tables("Table").Rows.Count = 0 Then
- Comm = New SqlClient.SqlCommand("INSERT INTO UserActivations (UserID,BookID,DeviceID,Date,Time) VALUES (" & UserID & "," & BookID & ",'" & Device & "'," & Get_Shamsi() & ",'" & Get_Time() & "')", Cnn)
- Comm.ExecuteNonQuery()
- End If
- Else
- DS = New DataSet()
- DA = New SqlClient.SqlDataAdapter("SELECT SampleBookPath From Books WHERE ID = " & BookIDs.Split(";").GetValue(i).ToString.Replace("SB", ""), Cnn)
- DA.Fill(DS, "Table")
- If DS.Tables("Table").Rows.Count <> 0 Then
- If Trim(DS.Tables("Table").Rows(0).Item("SampleBookPath")) <> "" Then
- Comm = New SqlClient.SqlCommand("DELETE FROM SampleInvoices WHERE BookID = " & BookIDs.Split(";").GetValue(i).ToString.Replace("SB", "") & " AND UserID = " & UserID, Cnn, Trans)
- Comm.ExecuteNonQuery()
- Dim DS1 As New DataSet()
- Dim DA1 As New SqlClient.SqlDataAdapter("SELECT BookID From Invoices WHERE UserID = " & UserID & " AND BookID = " & BookIDs.Split(";").GetValue(i).ToString.Replace("SB", ""), Cnn)
- DA1.Fill(DS1, "Table")
- If DS1.Tables("Table").Rows.Count = 0 Then
- Comm = New SqlClient.SqlCommand("INSERT INTO SampleInvoices (ID,BookID,UserID,Date,Time) VALUES (" & Gen_InvoiceID() & "," & BookIDs.Split(";").GetValue(i).ToString.Replace("SB", "") & "," & UserID & "," & Get_Shamsi() & ",'" & Get_Time() & "')", Cnn, Trans)
- Comm.ExecuteNonQuery()
- End If
- End If
- End If
- End If
- Next
- Trans.Commit()
- Return "SUCCESS"
- End If
- Return "WRONG"
- Catch ex As Exception
- SaveError(ex)
- Return ex.Message
- Finally
- Cnn.Close()
- End Try
- End Function
Add Comment
Please, Sign In to add comment