Advertisement
Guest User

Untitled

a guest
May 5th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.01 KB | None | 0 0
  1. Imports System.Data.Odbc
  2. Imports System.Random
  3. Imports System.Data.SqlClient
  4.  
  5.  
  6. Public Class OrderForm
  7.     Inherits System.Web.UI.Page
  8.  
  9.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  10.         medID.Text = Request.QueryString("mediaID")
  11.         MEDCATPR.Text = Request.QueryString("MEDCATPR")
  12.         medNM.Text = Request.QueryString("medNM")
  13.         mediaLink.Attributes.Add("src", Request.QueryString("mediaLink"))
  14.     End Sub
  15.  
  16.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  17.         placeOrder()
  18.     End Sub
  19.  
  20.     Protected Sub radioYes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioYes.CheckedChanged
  21.         Dim random As New Random()
  22.         Dim contNum As Integer = random.Next(1000000)
  23.         txtContNum.Text = contNum.ToString
  24.         txtContNum.Enabled = False
  25.  
  26.         lblFName.Visible = True
  27.         txtFName.Visible = True
  28.         lblLName.Visible = True
  29.         txtLName.Visible = True
  30.         'lblTitle.Visible = True
  31.         'listTitle.Visible = True
  32.         lblAddress.Visible = True
  33.         txtAddress.Visible = True
  34.         lblCity.Visible = True
  35.         txtCity.Visible = True
  36.         lblState.Visible = True
  37.         txtState.Visible = True
  38.         lblZip.Visible = True
  39.         txtZip.Visible = True
  40.         lblPhone.Visible = True
  41.         txtPhone.Visible = True
  42.         lblEmail.Visible = True
  43.         txtEmail.Visible = True
  44.  
  45.     End Sub
  46.  
  47.     Protected Sub radioNo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioNo.CheckedChanged
  48.         txtContNum.Enabled = True
  49.        
  50.         lblFName.Visible = False
  51.         txtFName.Visible = False
  52.         lblLName.Visible = False
  53.         txtLName.Visible = False
  54.         lblTitle.Visible = False
  55.         listTitle.Visible = False
  56.         lblAddress.Visible = False
  57.         txtAddress.Visible = False
  58.         lblCity.Visible = False
  59.         txtCity.Visible = False
  60.         lblState.Visible = False
  61.         txtState.Visible = False
  62.         lblZip.Visible = False
  63.         txtZip.Visible = False
  64.         lblPhone.Visible = False
  65.         txtPhone.Visible = False
  66.         lblEmail.Visible = False
  67.         txtEmail.Visible = False
  68.  
  69.     End Sub
  70.  
  71.  
  72.     Public Function getMediaValue(ByVal value As String) As String
  73.         Dim parameter As String = Nothing
  74.         MsgBox("returning " + value)
  75.         Select Case value
  76.             Case "medID"
  77.                 parameter = medID.Text
  78.             Case "MEDCATPR"
  79.                 MsgBox("stupid") ' = MEDCATPR.Text
  80.             Case "medNM"
  81.                 parameter = medNM.Text
  82.             Case "mediaText"
  83.                 parameter = mediaText.Text
  84.             Case Else
  85.                 parameter = "didn't work"
  86.         End Select
  87.         MsgBox(parameter)
  88.         Return parameter
  89.     End Function
  90.  
  91.     '
  92.     'This should go in the order class, but I can't get it to work
  93.     '
  94.     Public Sub placeOrder()
  95.         Try
  96.  
  97.             'Dim conn = "Driver={MySQL ODBC 5.1 Driver};Server='173.15.24.2';Database=mydb; User=root;Password=password;Option=3;"
  98.             Dim conn As String = "Driver={MySQL ODBC 5.1 Driver};Server=173.15.24.2;Database=wsc; User=root;Password=Viku1988!;Option=3;"
  99.  
  100.             Dim dbConn2 As New OdbcConnection(conn)
  101.             dbConn2.Open()
  102.  
  103.             'Dim sql As String = "INSERT INTO order (medID, ordID, contNum, empID, ordTO, medQuan, mediaText) VALUES('medID','ordID','contNum','empID','ordTO','medQuan', 'mediaText')"
  104.             'Dim sql As String = "INSERT INTO wsc.order (medID, ordID, contNum, medQuan, mediaText) VALUES('a','1','2','2', 'abc')"
  105.  
  106.  
  107.             'put order data values in correct format
  108.             Dim random As New Random()
  109.             Dim orderID As Integer = random.Next(1000000)
  110.             Dim price As Integer = CInt(MEDCATPR.Text)
  111.             Dim quantity As Decimal = CDec(medQuan.SelectedValue)
  112.             Dim contNum As Integer = CInt(txtContNum.Text)
  113.             Dim ordTotal As Decimal = price * quantity
  114.  
  115.  
  116.             'put customer data values in correct format
  117.             'Dim Zip As Integer = CInt(txtZip.Text)
  118.             'Dim title As String = listTitle.SelectedValue
  119.             'Dim Phone As Integer = CInt(txtPhone.Text)
  120.             Dim passWord As String = "default"
  121.             'Dim title As String = "default"
  122.  
  123.            
  124.  
  125.             MsgBox(mediaText.Text)
  126.             Dim sql As String = "INSERT INTO wsc.order (medID, contNum, medQuan, mediaText, ordTotal) VALUES('" + medID.Text + "','" + contNum.ToString + "','" + quantity.ToString + "', '" + mediaText.Text + "', '" + ordTotal.ToString + "')"
  127.             Dim sql2 As String = "INSERT INTO wsc.customer (contNum, Fname, Lname, ADD, CITY, ST, ZIP, phNUM, PASS, EMAIL) VALUES('" + contNum.ToString + "','" + txtFName.Text + "','" + txtLName.Text + "', '" + txtAddress.Text + "', '" + txtCity.Text + "', '" + txtState.Text + "', '" + txtZip.Text + "', '" + txtPhone.Text + "','" + passWord + "', '" + txtEmail.Text + "')"
  128.  
  129.  
  130.  
  131.             Dim command As New OdbcCommand
  132.             command.Connection = dbConn2
  133.             command.CommandText = sql2
  134.             command.ExecuteNonQuery()
  135.  
  136.  
  137.             Dim command2 As New OdbcCommand
  138.             command2.Connection = dbConn2
  139.             command2.CommandText = sql
  140.             command.ExecuteNonQuery()
  141.        
  142.  
  143.             dbConn2.Close()
  144.  
  145.             'command.Parameters.AddWithValue("medID", medID.Text)
  146.             'command.Parameters.AddWithValue("ordID", orderID)
  147.             'command.Parameters.AddWithValue("contNum", contNum)
  148.             'command.Parameters.AddWithValue("empID", empID)
  149.             'command.Parameters.AddWithValue("ordTO", total)
  150.             'command.Parameters.AddWithValue("medQuan", quantity)
  151.             'command.Parameters.AddWithValue("mediaText", mediaText.Text)
  152.  
  153.  
  154.             'command.Parameters.Add("@medID", OdbcType.NVarChar, 25).Value = getMediaValue("medID")
  155.  
  156.             'Dim orderID As Integer = CInt(getMediaValue("ordID"))
  157.             'command.Parameters.Add("@ordID", OdbcType.Int, 8).Value = orderID
  158.  
  159.             ''not sure about these
  160.             'command.Parameters.Add("@contNum", OdbcType.Int, 10).Value = 123456
  161.             'command.Parameters.Add("@empID", OdbcType.Int, 8).Value = 11111111
  162.  
  163.             'Dim price As Decimal = CDec(getMediaValue(MEDCATPR.Text))
  164.             'Dim quantity As Decimal = CDec(getMediaValue(medQuan.SelectedValue))
  165.             'Dim total As Decimal = price * quantity
  166.             'command.Parameters.Add("@ordTO", OdbcType.Decimal, 3, 2).Value = total
  167.  
  168.             'command.Parameters.Add("@medQuan", OdbcType.Int, 11).Value = quantity
  169.  
  170.  
  171.  
  172.             'Dim reader As OdbcDataReader = command.ExecuteReader
  173.  
  174.             MsgBox("Your order was placed successfully")
  175.  
  176.         Catch ex As Exception
  177.             'MsgBox("Your order was not able to placed at this time")
  178.             MsgBox(ex.Message)
  179.         End Try
  180.     End Sub
  181.  
  182. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement