我有一个Crystal Report,我使用报告查看器列出3个下拉框。用户可以从每个框中选择过滤(例如,firstname和lastname下拉列表,他们可以选择“contains”,以“,”等开头。然后另一个下拉列表包含“大于”,“小于”,每个下拉列表都包含一个文本框,用户可以根据自己的选择进行过滤。
我已经能够将firstname和lastname下拉列表与recordselectionformula中的每一个一起使用。但是,当我尝试为销售添加公式时,我不断收到错误。我已经捣乱了几个小时并研究了如何在recordselectionformula中添加多个公式,我用它来成功添加名字和姓氏,但是添加销售公式的每种方法都不起作用。单独(没有名字和姓氏公式)销售公式正常,但我无法让所有3个人一起工作。
感谢任何帮助。下面是我到目前为止的代码。
`Public Class Form1
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
`