All pastes #413956 Raw Edit

Something

public text v1 · immutable
#413956 ·published 2007-03-28 19:57 UTC
rendered paste body
Public Class Form1
    
    ' **** DECLARED CONSTANTS FOR WORKING WITH SECTION ARRAY AND MOTOR DESCRIPTION BUILDING ****
    Private Const FINISHED_GOOD As Integer = 0
    Private Const SERVOLOC_SERIES As Integer = 1
    Private Const FRAME_SIZE As Integer = 2
    Private Const STACK_LENGTH As Integer = 3
    Private Const MOTOR_KE As Integer = 4
    Private Const VOLTAGE As Integer = 5
    Private Const MOUNTING_OPTION As Integer = 6
    Private Const FEEDBACK As Integer = 7
    Private Const TERMINATION As Integer = 8
    Private Const BRAKE_OPTION As Integer = 9
    Private Const OTHER_OPTIONS As Integer = 10
    ' **** SECTION ARRAY FOR MOTOR DESCRIPTIONS ****
    Dim section(10) As String
    ' **** PRICING ARRAY FOR DETERMINING PRICES FOR VARIOUS PRICE GROUPS ****
    Dim pricing(11) As Single
    ' **** OTHER VARIABLES ****
    Dim list As Single
    Dim cost As Single
    Dim counter As Integer
    Dim price As Single
    Dim normalpart As Boolean

    Dim s As String


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'dsIntrol.TestQuote' table. You can move, or remove it, as needed.
        Me.taTestQuote.Fill(Me.dsIntrol.TestQuote)
        'TODO: This line of code loads data into the 'dsIntrol.pricelist' table. You can move, or remove it, as needed.
        Me.taPricelist.Fill(Me.dsIntrol.pricelist)
        btnadd.Enabled = False
        grpQuote.Enabled = False
        grpQuoteDetail.Enabled = False
        'btnnew.Enabled = False
        lblquote.Text = "$0.00"
        btnmake.Enabled = False
        cleartextboxes()
        calcpricing()
        calcprice()
        btnprint.Enabled = False
        btnPrint2.Enabled = False
        DateTimePicker1.Value = DateTime.Now()
        btnmotordesc.Enabled = False
    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        Try
            Me.Validate()
            bspricelist.EndEdit()
            daPricelist.Update(dsIntrol.pricelist)
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.taPricelist.Fill(Me.dsIntrol.pricelist)
    End Sub

    Private Function GetRow() As dsIntrol.pricelistRow
        Dim drv As DataRowView
        drv = bspricelist.Current
        GetRow = drv.Row
    End Function

    Private Sub cleartextboxes()
        txtuser1.Text = ""
        txtuser2.Text = ""
        txtuser3.Text = ""
        txtoem1.Text = ""
        txtoem2.Text = ""
        txtoem3.Text = ""
        txtreseller1.Text = ""
        txtreseller2.Text = ""
        txtreseller3.Text = ""
        txtdistributor1.Text = ""
        txtdistributor2.Text = ""
        txtdistributor3.Text = ""
    End Sub

    Private Sub calcprice()
        Try
            If cbxcustomer.Text = "User" Then
                If numqty.Value < 5 Then
                    price = pricing(0) * numqty.Value
                ElseIf numqty.Value < 25 Then
                    price = pricing(1) * numqty.Value
                Else
                    price = pricing(2) * numqty.Value
                End If
            ElseIf cbxcustomer.Text = "OEM" Then
                If numqty.Value < 5 Then
                    price = pricing(3) * numqty.Value
                ElseIf numqty.Value < 25 Then
                    price = pricing(4) * numqty.Value
                Else
                    price = pricing(5) * numqty.Value
                End If
            ElseIf cbxcustomer.Text = "Reseller" Then
                If numqty.Value < 5 Then
                    price = pricing(6) * numqty.Value
                ElseIf numqty.Value < 25 Then
                    price = pricing(7) * numqty.Value
                Else
                    price = pricing(8) * numqty.Value
                End If
            ElseIf cbxcustomer.Text = "Distributor" Then
                If numqty.Value < 5 Then
                    price = pricing(9) * numqty.Value
                ElseIf numqty.Value < 25 Then
                    price = pricing(10) * numqty.Value
                Else
                    price = pricing(11) * numqty.Value
                End If
            End If
            lblquote.Text = "$" & price & ".00"
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub calcpricing()
        Try
            If txtlistprice.Text <> Nothing And txtcost.Text <> Nothing Then
                If chkmotor.Checked = False Then
                    'grab the list value
                    list = CSng(txtlistprice.Text)
                    pricing(0) = list
                    pricing(1) = RoundingRoutine(list, 0.95)
                    pricing(2) = RoundingRoutine(list, 0.9)
                    pricing(3) = RoundingRoutine(list, 0.9)
                    pricing(4) = RoundingRoutine(list, 0.85)
                    pricing(5) = RoundingRoutine(list, 0.8)
                    pricing(6) = RoundingRoutine(list, 0.82)
                    pricing(7) = RoundingRoutine(list, 0.8)
                    pricing(8) = RoundingRoutine(list, 0.75)
                    pricing(9) = RoundingRoutine(list, 0.65)
                    pricing(10) = RoundingRoutine(list, 0.6)
                    pricing(11) = 0.0
                    'populate the boxes
                    normalpart = True
                    populateboxes()
                Else
                    If chkaccessory.Checked = True Then
                        'start accessory pricing
                        normalpart = False
                        list = CSng(txtlistprice.Text)
                        pricing(0) = list
                        pricing(1) = RoundingRoutine(list, 0.95)
                        pricing(2) = RoundingRoutine(list, 0.95)
                        pricing(3) = RoundingRoutine(list, 0.91)
                        pricing(4) = RoundingRoutine(list, 0.89)
                        pricing(5) = RoundingRoutine(list, 0.89)
                        pricing(6) = RoundingRoutine(list, 0.91)
                        pricing(7) = RoundingRoutine(list, 0.89)
                        pricing(8) = RoundingRoutine(list, 0.89)
                        pricing(9) = RoundingRoutine(list, 0.83)
                        pricing(10) = RoundingRoutine(list, 0.8)
                        pricing(11) = RoundingRoutine(list, 0.8)
                        populateboxes()
                    Else
                        'start motor pricing
                        normalpart = False
                        list = CSng(txtlistprice.Text)
                        pricing(0) = list
                        pricing(1) = roundingroutine(list, 0.95)
                        pricing(2) = roundingroutine(list, 0.95)
                        pricing(3) = roundingroutine(list, 0.9)
                        pricing(4) = roundingroutine(list, 0.85)
                        pricing(5) = roundingroutine(list, 0.85)
                        pricing(6) = roundingroutine(list, 0.9)
                        pricing(7) = roundingroutine(list, 0.85)
                        pricing(8) = roundingroutine(list, 0.95)
                        pricing(9) = roundingroutine(list, 0.8)
                        pricing(10) = roundingroutine(list, 0.75)
                        pricing(11) = roundingroutine(list, 0.75)
                        populateboxes()
                    End If
                End If
            End If
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub buildmotordescription()

        Dim firsthash As Integer = 0
        Dim secondhash As Integer = 0
        Dim prodnum As String
        Dim tempchar As String = ""
        Dim length As Integer
        Dim special As Boolean = False
        Dim description As String = ""
        Dim enter As String = vbCrLf
        prodnum = IntrolProductNumberTextBox.Text

        Try
            '****   FIND THE FIRST HASH ****
            tempchar = prodnum.IndexOf("-")
            firsthash = tempchar
            tempchar = 0
            '****   FIND THE SECOND HASH ****
            tempchar = prodnum.Substring(prodnum.IndexOf("-") + 1).IndexOf("-")
            secondhash = (tempchar + firsthash) + 1
            length = Len(prodnum)
            If (length - secondhash) > 7 Then
                special = True
            End If
            ' **** POPULATE THE ARRAY WITH THE FIRST SECTION OF MOTOR DATA ****
            section(STACK_LENGTH) = prodnum.Substring(firsthash - 1, 1)
            section(FINISHED_GOOD) = prodnum.Substring(0, 1)
            section(SERVOLOC_SERIES) = prodnum.Substring(1, 2)
            If firsthash > 6 Then
                section(FRAME_SIZE) = prodnum.Substring(3, 3)
            Else
                section(FRAME_SIZE) = prodnum.Substring(3, 2)
            End If
            ' **** POPULATE THE ARRAY WITH THE SECOND SECTION OF MOTOR DATA ****
            section(MOUNTING_OPTION) = prodnum.Substring(secondhash - 1, 1)
            section(VOLTAGE) = prodnum.Substring(secondhash - 2, 1)
            If (secondhash - firsthash) > 5 Then
                section(MOTOR_KE) = prodnum.Substring(firsthash + 1, 3)
            Else
                section(MOTOR_KE) = prodnum.Substring(firsthash + 1, 2)
            End If
            ' **** POPULATE THE ARRAY WITH THE THIRD SECTION OF MOTOR DATA ****
            section(FEEDBACK) = prodnum.Substring(secondhash + 1, 4)
            section(TERMINATION) = prodnum.Substring(secondhash + 5, 1)
            section(BRAKE_OPTION) = prodnum.Substring(secondhash + 6, 1)
            If special = True Then
                section(OTHER_OPTIONS) = prodnum.Substring(secondhash + 7, 1)
            End If

            ' **** START ASSEMBLING DESCRIPTION ****
            ' **** CONVERT FRAME SIZE ****
            Select Case section(FRAME_SIZE)
                Case "50"
                    section(FRAME_SIZE) = "2"
                Case "80"
                    section(FRAME_SIZE) = "3"
                Case "97"
                    section(FRAME_SIZE) = "4"
                Case "130"
                    section(FRAME_SIZE) = "6"
                Case "180"
                    section(FRAME_SIZE) = "8"
            End Select
            ' **** CONVERT STACK LENGTH ****
            If section(FRAME_SIZE) = 8 Then
                Select Case section(STACK_LENGTH)
                    Case "B"
                        section(STACK_LENGTH) = "1"
                    Case "C"
                        section(STACK_LENGTH) = "1.5"
                    Case "D"
                        section(STACK_LENGTH) = "1.75"
                    Case "G"
                        section(STACK_LENGTH) = "2"
                    Case "J"
                        section(STACK_LENGTH) = "4"
                    Case "K"
                        section(STACK_LENGTH) = "Large 8-inch special magnet"
                End Select
            Else
                Select Case section(STACK_LENGTH)
                    Case "A"
                        section(STACK_LENGTH) = "1"
                    Case "B"
                        section(STACK_LENGTH) = "2"
                    Case "C"
                        section(STACK_LENGTH) = "3"
                    Case "D"
                        section(STACK_LENGTH) = "4"
                        'Case "S"
                        '    section(STACK_LENGTH) = "Special"
                End Select
            End If
            ' **** CONVERT VOLTAGE ****
            Select Case section(VOLTAGE)
                Case "G"
                    section(VOLTAGE) = "24"
                Case "H"
                    section(VOLTAGE) = "48"
                Case "I"
                    section(VOLTAGE) = "115"
                Case "J"
                    section(VOLTAGE) = "230"
                Case "K"
                    section(VOLTAGE) = "450"
                    'Case "S"
                    '    section(VOLTAGE) = "Special"
            End Select
            ' **** CONVERT MOUNTING OPTION ****
            Select Case section(MOUNTING_OPTION)
                Case "E"
                    section(MOUNTING_OPTION) = "English"
                Case "M"
                    section(MOUNTING_OPTION) = "Metric"
                    'Case "S"
                    '    section(MOUNTING_OPTION) = "Special"
            End Select
            ' **** CONVERT FEEDBACK ****
            Select Case section(FEEDBACK)
                Case "1000"
                    section(FEEDBACK) = "1000 PPR communicating encoder feedback"
                Case "1024"
                    section(FEEDBACK) = "1024 PPR communicating encoder feedback"
                Case "2000"
                    section(FEEDBACK) = "2000 PPR communicating encoder feedback"
                Case "2048"
                    section(FEEDBACK) = "2048 PPR communicating encoder feedback"
                Case "HRES"
                    section(FEEDBACK) = "Hi-Gain Resolver"
            End Select
            ' **** CONVERT TERMINATION ****
            Select Case section(TERMINATION)
                Case "M"
                    section(TERMINATION) = "MS connector"
                Case "N"
                    section(TERMINATION) = "NPT connector"
                Case "P"
                    section(TERMINATION) = "Pigtail connector"
                Case "S"
                    section(TERMINATION) = "Special connector"
                Case "1"
                    section(TERMINATION) = "18-inch single cord exit w/Conexall connector"
                Case "2"
                    section(TERMINATION) = "wire exit through back plate"
                Case "3"
                    section(TERMINATION) = "side front facing wire exit"
                Case "4"
                    section(TERMINATION) = "side rear facing wire exit"
                Case "E"
                    section(TERMINATION) = "Emerson MG style connector"
                Case "D"
                    section(TERMINATION) = "Emerson DXM"
            End Select
            ' **** CONVERT BRAKE_OPTION ****
            Select Case section(BRAKE_OPTION)
                Case "B"
                    section(BRAKE_OPTION) = "24"
                Case "N"
                    section(BRAKE_OPTION) = "No Brake"
            End Select
            ' ***** START BUILDING DESCRIPTION ****
            description = "Introl " & prodnum.Substring(1, length - 1) & ", " & section(FRAME_SIZE) & " inch brushless servo motor, " & section(STACK_LENGTH) & " stack length with " & section(FEEDBACK) & " and " & section(TERMINATION)
            If section(BRAKE_OPTION) = "24" Then
                description = description + " with " & section(BRAKE_OPTION) & "VDC spring applied brake."
            Else
                description = description + "."
            End If
            DescriptionTextBox.Text = description
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try


    End Sub

    Private Sub populateboxes()
        txtuser1.Text = CStr("$" & pricing(0) & ".00")
        txtuser2.Text = CStr("$" & pricing(1) & ".00")
        txtuser3.Text = CStr("$" & pricing(2) & ".00")
        txtoem1.Text = CStr("$" & pricing(3) & ".00")
        txtoem2.Text = CStr("$" & pricing(4) & ".00")
        txtoem3.Text = CStr("$" & pricing(5) & ".00")
        txtreseller1.Text = CStr("$" & pricing(6) & ".00")
        txtreseller2.Text = CStr("$" & pricing(7) & ".00")
        txtreseller3.Text = CStr("$" & pricing(8) & ".00")
        txtdistributor1.Text = CStr("$" & pricing(9) & ".00")
        txtdistributor2.Text = CStr("$" & pricing(10) & ".00")
        txtdistributor3.Text = CStr("$" & pricing(11) & ".00")
        If normalpart = True Then
            txtdistributor3.Text = "Call for Pricing"
        End If
    End Sub

    Private Sub txtlistprice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtlistprice.TextChanged
        cleartextboxes()
        calcpricing()
        calcprice()
    End Sub

    Private Sub AccessoryCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkaccessory.CheckedChanged
        'this ensures if Accessory checkbox is checked, the motor checkbox will also set to checked since accessories are
        'accessories to motors and follow the motor logic structure in the pricing procedure.
        chkmotor.Checked = True
    End Sub

    Private Sub numqty_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numqty.ValueChanged
        'this recalculates a item-line quantity pricing for different users when the user changes the quanity
        'the pricing calculation is fired again to reupdate the quote price.
        calcprice()
    End Sub

    Private Sub cbxcustomer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxcustomer.SelectedIndexChanged
        'this recalculates a item-line quantity pricing for different users when the user changes the status of a customer
        'type the pricing calculation is fired again to reupdate the quote price.
        calcprice()
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Try
            Me.taPricelist.FillByProductNumber(Me.dsIntrol.pricelist, ToolStripTextBox1.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Try
            Me.taPricelist.FillByMotorNumber(Me.dsIntrol.pricelist, ToolStripTextBox1.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Try
            Me.taPricelist.FillByDescription(Me.dsIntrol.pricelist, ToolStripTextBox1.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        Try
            Me.taPricelist.Fill(Me.dsIntrol.pricelist)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
        'TODO: This line of code loads data into the 'dsIntrol.Customers' table. You can move, or remove it, as needed.
        Me.taCustomers.Fill(Me.dsIntrol.Customers)
        Dim highquote As Long
        btnmake.Enabled = True
        btnnew.Enabled = False
        grpQuote.Enabled = True
        cnIntrol.Open()
        highquote = cmdGetQuoteNum.ExecuteScalar
        txtquotenum.Text = (highquote + 1).ToString
        cnIntrol.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        My.Forms.Form2.ShowDialog()
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmake.Click
        TextBox19.Text = CType(txtquotenum.Text, String)
        btnadd.Enabled = True
        grpQuote.Enabled = False
        grpQuoteDetail.Enabled = True

        Me.taTestQuote.Fill(Me.dsIntrol.TestQuote)
        Dim drnewquote As DataRow
        drnewquote = dsIntrol.TestQuote.NewRow()
        drnewquote.Item("Customer") = cbxtradingname.Text
        drnewquote.Item("Address1") = TextBox3.Text + " " + TextBox4.Text
        drnewquote.Item("Address2") = TextBox4.Text
        drnewquote.Item("Address3") = TextBox5.Text + ", " + TextBox6.Text + "  " + TextBox7.Text + "  " + TextBox8.Text
        drnewquote.Item("City") = TextBox5.Text
        drnewquote.Item("State") = TextBox6.Text
        drnewquote.Item("Zip") = TextBox7.Text
        drnewquote.Item("Country") = TextBox8.Text
        drnewquote.Item("Quotenumber") = txtquotenum.Text
        drnewquote.Item("Quotedate") = DateTimePicker1.Text
        drnewquote.Item("Quoterep") = TextBox9.Text
        drnewquote.Item("Quoteshipdate") = TextBox2.Text
        drnewquote.Item("Quoteshipmethod") = ComboBox2.Text
        drnewquote.Item("Quotefob") = ComboBox3.Text
        drnewquote.Item("Quoteterms") = ComboBox1.Text
        dsIntrol.TestQuote.Rows.Add(drnewquote)
        Try
            Me.Validate()
            bsTestQuote.EndEdit()
            taTestQuote.Update(dsIntrol.TestQuote)
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
        'TODO: This line of code loads data into the 'dsIntrol.TestQuoteDetail' table. You can move, or remove it, as needed.
        'Me.taTestQuoteDetail.Fill(Me.daTestQuoteDetail)
        Me.taTestQuoteDetail.FillBy(Me.dsIntrol.TestQuoteDetail, TextBox19.Text)
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        Try
            btnprint.Enabled = False
            btnPrint2.Enabled = False
            grpQuoteDetail.Enabled = True
            Dim drnew As DataRow
            drnew = dsIntrol.TestQuoteDetail.NewRow()
            drnew.Item("Partnumber") = IntrolProductNumberTextBox.Text.ToString()
            drnew.Item("Quotenumber") = TextBox19.Text.ToString()
            drnew.Item("Price") = CType(CType(price.ToString + ".0000", Short) / CType(numqty.Text.ToString, Short), String) + ".0000"
            drnew.Item("Quantity") = numqty.Text.ToString()
            drnew.Item("Description") = DescriptionTextBox.Text.ToString()
            drnew.Item("ExtPrice") = price.ToString() + ".0000"
            dsIntrol.TestQuoteDetail.Rows.Add(drnew)
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            Me.Validate()
            bsTestQuoteDetail.EndEdit()
            daTestQuoteDetail.Update(dsIntrol.TestQuoteDetail)
            'taTestQuoteDetail.Update(dsIntrol.TestQuoteDetail)
            btnprint.Enabled = True
            btnPrint2.Enabled = True
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
        quotenumber = TextBox19.Text
        My.Forms.Form3.ShowDialog()
    End Sub

    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint2.Click
        quotenumber = TextBox19.Text
        My.Forms.Form4.ShowDialog()
    End Sub

    Private Sub TestQuoteDetailDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles TestQuoteDetailDataGridView.CellBeginEdit
        btnprint.Enabled = False
        btnPrint2.Enabled = False
    End Sub

    Private Sub TestQuoteDetailDataGridView_RowsRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles TestQuoteDetailDataGridView.RowsRemoved
        btnprint.Enabled = False
        btnPrint2.Enabled = False
    End Sub

    Private Sub TestQuoteDetailDataGridView_RowStateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowStateChangedEventArgs) Handles TestQuoteDetailDataGridView.RowStateChanged
        btnprint.Enabled = False
        btnPrint2.Enabled = False
    End Sub

    Private Sub chkmotor_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkmotor.CheckedChanged
        If chkmotor.Checked = True Then
            btnmotordesc.Enabled = True
        Else
            btnmotordesc.Enabled = False
        End If
    End Sub

    Private Sub btnmotordesc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmotordesc.Click
        buildmotordescription()
    End Sub
End Class