Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.33 KB | None | 0 0
  1. Imports System.Data.Odbc
  2. Imports System.Data.SqlClient
  3.  
  4. Public Class OrderForm
  5.     Inherits System.Web.UI.Page
  6.  
  7.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8.         medID.Text = Request.QueryString("mediaID")
  9.         MEDCATPR.Text = Request.QueryString("MEDCATPR")
  10.         medNM.Text = Request.QueryString("medNM")
  11.         mediaLink.Attributes.Add("src", Request.QueryString("mediaLink"))
  12.     End Sub
  13.  
  14.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.         placeOrder()
  16.     End Sub
  17.  
  18.     Public Function getMediaValue(ByVal value As String) As String
  19.         Dim parameter As String = Nothing
  20.         MsgBox("returning " + value)
  21.         Select Case value
  22.             Case "medID"
  23.                 parameter = medID.Text
  24.             Case "MEDCATPR"
  25.                 MsgBox("stupid") ' = MEDCATPR.Text
  26.             Case "medNM"
  27.                 parameter = medNM.Text
  28.             Case "mediaText"
  29.                 parameter = mediaText.Text
  30.             Case Else
  31.                 parameter = "didn't work"
  32.         End Select
  33.         MsgBox(parameter)
  34.         Return parameter
  35.     End Function
  36.  
  37.     '
  38.     'This should go in the order class, but I can't get it to work
  39.     '
  40.     Public Sub placeOrder()
  41.         Try
  42.  
  43.             'Dim conn = "Driver={MySQL ODBC 5.1 Driver};Server='173.15.24.2';Database=mydb; User=root;Password=password;Option=3;"
  44.             Dim conn As String = "Driver={MySQL ODBC 5.1 Driver};Server=173.15.24.2;Database=wsc; User=root;Password=Viku1988!;Option=3;"
  45.  
  46.             Dim dbConn2 As New OdbcConnection(conn)
  47.             dbConn2.Open()
  48.  
  49.             'Dim sql As String = "INSERT INTO order (medID, ordID, contNum, empID, ordTO, medQuan, mediaText) VALUES(@medID,@ordID,@contNum,@empID,@ordTO,@medQuan, @mediaText)"
  50.             Dim sql As String = "INSERT INTO order (`medID`, `ordID`, `contNum`, `medQuan`, `mediaText`) VALUES('a',1,2,2, 'abc')"
  51.  
  52.  
  53.             'put data values in correct format
  54.             Dim orderID As Integer = 1010101
  55.             Dim price As Integer = CInt(MEDCATPR.Text)
  56.             Dim quantity As Decimal = CDec(medQuan.SelectedValue)
  57.             Dim total As Decimal = price * quantity
  58.             Dim contNum As Integer = 11
  59.             Dim empID As Integer = 22
  60.             'MsgBox(mediaText.Text)
  61.             'Dim sql As String = "INSERT INTO order (medID, ordID, contNum, medQuan, mediaText) VALUES('" + medID.Text + "','" + orderID.ToString + "','" + contNum.ToString + "','" + quantity.ToString + "', '" + mediaText.Text + "')"
  62.  
  63.             Dim command As New OdbcCommand
  64.             command.Connection = dbConn2
  65.             command.CommandText = sql
  66.  
  67.             'command.Parameters.AddWithValue("medID", medID.Text)
  68.             'command.Parameters.AddWithValue("ordID", orderID)
  69.             'command.Parameters.AddWithValue("contNum", contNum)
  70.             'command.Parameters.AddWithValue("empID", empID)
  71.             'command.Parameters.AddWithValue("ordTO", total)
  72.             'command.Parameters.AddWithValue("medQuan", quantity)
  73.             'command.Parameters.AddWithValue("mediaText", mediaText.Text)
  74.  
  75.  
  76.             'command.Parameters.Add("@medID", OdbcType.NVarChar, 25).Value = getMediaValue("medID")
  77.  
  78.             'Dim orderID As Integer = CInt(getMediaValue("ordID"))
  79.             'command.Parameters.Add("@ordID", OdbcType.Int, 8).Value = orderID
  80.  
  81.             ''not sure about these
  82.             'command.Parameters.Add("@contNum", OdbcType.Int, 10).Value = 123456
  83.             'command.Parameters.Add("@empID", OdbcType.Int, 8).Value = 11111111
  84.  
  85.             'Dim price As Decimal = CDec(getMediaValue(MEDCATPR.Text))
  86.             'Dim quantity As Decimal = CDec(getMediaValue(medQuan.SelectedValue))
  87.             'Dim total As Decimal = price * quantity
  88.             'command.Parameters.Add("@ordTO", OdbcType.Decimal, 3, 2).Value = total
  89.  
  90.             'command.Parameters.Add("@medQuan", OdbcType.Int, 11).Value = quantity
  91.  
  92.             command.ExecuteNonQuery()
  93.  
  94.             'Dim reader As OdbcDataReader = command.ExecuteReader
  95.  
  96.             MsgBox("Your order was placed successfully")
  97.  
  98.         Catch ex As Exception
  99.             'MsgBox("Your order was not able to placed at this time")
  100.             MsgBox(ex.Message)
  101.         End Try
  102.     End Sub
  103.  
  104. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement