Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2008 Search criteria combination

$
0
0
hello,

I have a project that searches a record on the database based on the selected combination of fields criteria.all possible combination could reach up 900 criteria. and i have a code inside the function to perform this and this function will return a SQL query command to pull out the record. so far i have like 40,000K + lines of code it is a combination of IFs and select case, it would be estimated 100k+ line of code just for the search thing to finish.below is the screenshot of my program and and a few first part of the code. Please give me an advice if I am doing the right thing of coding because it takes a like 5 to 10 to minutes to process the code, sometimes it crashes the program.

Attachment 96765

and here's my codes
Code:


Private Function _subTiresearch() As String
        Dim SqlString As String = ""
        'convert  the cost currency value into decimal
        Dim iCost_From As Double = cost_range_from_entry.SelectedItem.ToString.Substring(1, cost_range_from_entry.SelectedItem.ToString.Count - 1)
        Dim iCost_To As Double = 0
        If cost_range_to_entry.SelectedItem.ToString = "(Any)" Then
            iCost_To = 0
        Else
            iCost_To = cost_range_to_entry.SelectedItem.ToString.Substring(1, cost_range_to_entry.SelectedItem.ToString.Count - 1)
        End If

        'MsgBox(type_combobox.Items.Count - 1)


        Select Case type_combobox.SelectedIndex ' ####################################' TIRE BRAND########################                     
            Case type_combobox.Items.Count - 1 ' Any  ------------------------------------------1
                Select Case ID_options.SelectedIndex ' ------------------------------------------1.1    '############ tire id ###########
                    Case 0 'Contains          --------------------------------------------------1.1.1
                        'check to see of ID entry is empty or not
                        If String.IsNullOrEmpty(ID_entry.Text) Then '----------------------------1.1.1.1

                            Select Case size_entry.SelectedIndex    '----------------------------1.1.1.1.1 ########## TIRE SIZE #######
                                Case size_entry.Items.Count - 1 'Any tires-----------------------1.1.1.1.1.1
                                    If cost_range_from_entry.SelectedIndex >= 0 And (cost_range_to_entry.SelectedIndex = cost_range_to_entry.Items.Count - 1 Or cost_range_to_entry.SelectedIndex = 0) Then '-----  -1.1.1.1.1.1.1

                                        Select Case location_entry.SelectedIndex                        '################## TIRE LOCATION ########                                                          '-----  -1.1.1.1.1.1.1.1
                                            Case location_entry.Items.Count - 1 '                                                                                                                          '-----  -1.1.1.1.1.1.1.1.1     

                                                If mileage_from_entry.SelectedIndex >= 0 And (mileage_to_entry.SelectedIndex = mileage_to_entry.Items.Count - 1 Or mileage_to_entry.SelectedIndex = 0) Then '--------1.1.1.1.1.1.1.1.1.1 ################# Tire Mielage #####################
                                                    Select Case bus_ID_choices.SelectedIndex            '############################# BUS ID ##############################
                                                        Case 0 ' contains
                                                            If Not String.IsNullOrEmpty(bus_ID_entry.Text) Then
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [BusNumber] LIKE '%" & bus_ID_entry.Text & "%'"
                                                            Else
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString)
                                                            End If
                                                        Case 1 ' Matches
                                                            If Not String.IsNullOrEmpty(bus_ID_entry.Text) Then
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [BusNumber] = '" & bus_ID_entry.Text & "'"
                                                            Else
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString)
                                                            End If
                                                        Case Else
                                                            SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString)
                                                    End Select



                                                    SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString)
                                                ElseIf mileage_from_entry.SelectedIndex >= 0 And (mileage_to_entry.SelectedIndex <> mileage_to_entry.Items.Count - 1 Or mileage_to_entry.SelectedIndex <> 0) Then '--1.1.1.1.1.1.1.1.1.2

                                                    Select Case bus_ID_choices.SelectedIndex            '############################# BUS ID ##############################
                                                        Case 0 ' contains
                                                            If Not String.IsNullOrEmpty(bus_ID_entry.Text) Then
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND ([MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [MileAge] <= " & CInt(mileage_to_entry.SelectedItem.ToString) & ") AND [BusNumber] LIKE '%" & bus_ID_entry.Text & "%'"
                                                            Else
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND ([MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [MileAge] <= " & CInt(mileage_to_entry.SelectedItem.ToString) & ")"
                                                            End If
                                                        Case 1 ' Matches
                                                            If Not String.IsNullOrEmpty(bus_ID_entry.Text) Then
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND ([MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [MileAge] <= " & CInt(mileage_to_entry.SelectedItem.ToString) & ") AND [BusNumber] = '" & bus_ID_entry.Text & "'"
                                                            Else
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND ([MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [MileAge] <= " & CInt(mileage_to_entry.SelectedItem.ToString) & ")"
                                                            End If
                                                        Case Else
                                                            SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND ([MileAge] >= " & CInt(mileage_from_entry.SelectedItem.ToString) & " AND [MileAge] <= " & CInt(mileage_to_entry.SelectedItem.ToString) & ")"
                                                    End Select


                                                Else                                                                                                                                                              '--1.1.1.1.1.1.1.1.1.3

                                                    Select Case bus_ID_choices.SelectedIndex            '############################# BUS ID ##############################
                                                        Case 0 ' contains
                                                            If Not String.IsNullOrEmpty(bus_ID_entry.Text) Then
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [BusNumber] LIKE '%" & bus_ID_entry.Text & "%'"
                                                            Else
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From
                                                            End If
                                                        Case 1 ' Matches
                                                            If Not String.IsNullOrEmpty(bus_ID_entry.Text) Then
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From & " AND [MileAge] <= " & CInt(mileage_to_entry.SelectedItem.ToString) & ") AND [BusNumber] = '" & bus_ID_entry.Text & "'"
                                                            Else
                                                                SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From
                                                            End If
                                                        Case Else
                                                            SqlString = "SELECT * FROM Tire WHERE tirecost> = " & iCost_From
                                                    End Select
                                                End If

Attached Images
 

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>