我有一个水晶报表,我在其中使用报表查看器列出 3 个下拉框。用户可以从每个框中选择过滤(例如,名字和姓氏下拉菜单,他们可以选择“包含”、以“开头”等。然后另一个下拉菜单包含“大于”、“小于”、等等。每个下拉列表下方都包含一个文本框,用户可以在其中选择进行过滤。
我已经能够让名字和姓氏下拉列表与记录选择公式中的每个下拉列表一起工作。但是,当我尝试添加销售公式时,我不断收到错误。我已经绞尽脑汁研究了几个小时,研究如何在记录选择公式中添加多个公式,我用它成功地添加了名字和姓氏,但是添加销售公式的所有方法都不起作用。销售公式本身(没有名字和姓氏公式)可以正常工作,但我无法让所有 3 个公式一起工作。
任何帮助表示赞赏。以下是我到目前为止的代码。
`公开课表1
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim reportToView As New CrystalReport1
'User inputs filters for first name
Dim firstname As String
Dim searchFirst As String
firstname = txtFirstName.Text
Dim firstnamesearch As String
'Begins with
If cboFirstName.SelectedIndex = 0 Then
searchFirst = firstname & "*"
'Ends with
ElseIf cboFirstName.SelectedIndex = 1 Then
searchFirst = "*" & firstname
'Contains
ElseIf cboFirstName.SelectedIndex = 2 Then
searchFirst = "*" & firstname & "*"
'Equals
ElseIf cboFirstName.SelectedIndex = 3 Then
searchFirst = firstname
End If
'User inputs filters for last name
Dim lastname As String
lastname = txtLastName.Text
Dim searchLast As String
Dim lastnamesearch As String
'Begins with
If cboLastName.SelectedIndex = 0 Then
searchLast = lastname & "*"
'Ends with
ElseIf cboLastName.SelectedIndex = 1 Then
searchLast = "*" & lastname
'Contains
ElseIf cboLastName.SelectedIndex = 2 Then
searchLast = "*" & lastname & "*"
'Equals
ElseIf cboLastName.SelectedIndex = 3 Then
searchLast = lastname
End If
'User inputs filters for sales data
Dim lastsales As String
lastsales = txtLastYearSales.Text
Dim searchSales As String
Dim salesearch As String
'If "Greater Than" chosen
If cboLastYearSales.SelectedIndex = 0 Then
searchSales = " >" + lastsales
'If "Less Than" chosen
ElseIf cboLastYearSales.SelectedIndex = 1 Then
searchSales = " < " + lastsales
'If "Equal" chosen
ElseIf cboLastYearSales.SelectedIndex = 2 Then
searchSales = " = " + lastsales
End If
'Dim firstnamesearch As String
firstnamesearch = "{Person_Contact.FirstName} like """ & searchFirst & """"
'Dim lastnamesearch As String
lastnamesearch = "{Person_Contact.LastName} like """ & searchLast & """"
'Dim salesearch As String
'(这是我要添加到下面的记录选择公式中的内容) salesearch = "{Sales_SalesPerson.SalesLastYear} " + searchSales
'AND formula (must select an option in all fields)
reportToView.DataDefinition.RecordSelectionFormula = "{Person_Contact.FirstName} like '" & searchFirst & "' AND {Person_Contact.LastName} like '" & searchLast & "'"
Me.CrystalReportViewer1.ReportSource = reportToView
End Sub
`