如图,通过“统计”按钮将textbox2中的字符串按“vbcrlf”、“;”及“:”逐级拆分,得到若干字符串,组成形成sql语句,每一个"vbcrlf"形成一个sql语句进行统计。统计表的个数与“vbcrlf”拆分后形成的字符串个数相同。现在需要对统计表进行合并,用于图表绘制。统计表合并得不到想要的结果。不知道代码的问题出在哪儿?
Dim d1,d2 As String
Dim kind,tongji As String
Dim sql As String
Dim str As String= e.Form.Controls("TextBox2").value
Dim n As Integer
Dim strs() As String
strs =str.replace(vbcr,"").Split(vblf)
n=strs.Length
Dim dts(n-1) As fxDataSource
For i As Integer = 0 To n-1
If strs(i)>"" Then
Dim s() As String=strs(i).Split(";")
For j As Integer = 0 To s.Length-1
If s(j)<>"" Then
If s(j).Contains("统计项目") Then
Dim ss() As String=s(j).Split(";")
For Each s1 As String In ss
tongji=s1.split(":")(1)
Next
End If
If s(j).contains("开始时间") Then
Dim ss() As String=s(j).Split(";")
For Each s1 As String In ss
If s1.split(":")(1)="无" Then
d1=""
Else
d1=s1.split(":")(1)
End If
Next
End If
If s(j).contains("截止时间") Then
Dim ss() As String=s(j).Split(";")
For Each s1 As String In ss
If s1.split(":")(1)="无" Then
d2=""
Else
d2=s1.split(":")(1)
End If
Next
End If
If s(j).contains("患者种类") Then
Dim ss() As String=s(j).Split(";")
For Each s1 As String In ss
kind=s1.split(":")(1)
Next
End If
End If
Next
If d1="" Then
If d2="" Then
If kind="无" OrElse kind="预约患者(登记时间)" Then
sql="select * from {基本情况}"
Else If kind="住院患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='已入院'"
Else If kind="推迟入院(登记时间)" Then
sql="select * from {基本情况} where 情况说明='推迟入院'"
Else If kind="失访患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='无法联系'"
Else If kind="入院患者(入院日期)" Then
sql="select * from {基本情况} where 情况说明='已入院'"
Else If kind="预约患者(入院日期)" Then
sql="select * from {基本情况} where (情况说明<>'推迟入院'or 情况说明<>'无法联系')"
End If
Else
If kind="无" OrElse kind="预约患者(登记时间)" Then
sql="select * from {基本情况} where 登记日期<d2"
Else If kind="住院患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='已入院' and 登记日期<#" & d2 & "#"
Else If kind="推迟入院(登记时间)" Then
sql="select * from {基本情况} where 情况说明='推迟入院'and 登记日期<#" & d2 & "#"
Else If kind="失访患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='无法联系'and 登记日期<#" & d2 & "#"
Else If kind="入院患者(入院日期)" Then
sql="select * from {基本情况} where 情况说明='已入院'and 预约日期<#" & d2 & "#"
Else If kind="预约患者(入院日期)" Then
sql="select * from {基本情况} where (情况说明<>'推迟入院'or 情况说明<>'无法联系') and 预约日期<#" & d2 & "#"
End If
End If
Else
If d2="" Then
If kind="无" OrElse kind="预约患者(登记时间)" Then
sql="select * from {基本情况} where 登记日期>#" & d1 & "#"
Else If kind="住院患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='已入院' And 登记日期>#" & d1 & "#"
Else If kind="推迟入院(登记时间)" Then
sql="select * from {基本情况} where 情况说明='推迟入院'and 登记日期>#" & d1 & "#"
Else If kind="失访患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='无法联系'and 登记日期>#" & d1 & "#"
Else If kind="入院患者(入院日期)" Then
sql= "select * from {基本情况} where 情况说明='已入院'and 预约日期>#" & d1 & "#"
Else If kind="预约患者(入院日期)" Then
sql="select * from {基本情况} where (情况说明<>'推迟入院'or 情况说明<>'无法联系') and 预约日期>#" & d1 & "#"
End If
Else
If kind="无" OrElse kind="预约患者(登记时间)" Then
sql="select * from {基本情况} where 登记日期<#" & d2 & "# And 登记日期>#" & d1 & "#"
Else If kind="住院患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='已入院' and 登记日期<#" & d2 & "# And 登记日期>#" & d1 & "#"
Else If kind="推迟入院(登记时间)" Then
sql="select * from {基本情况} where 情况说明='推迟入院'and 登记日期<#" & d2 & "# And 登记日期>#" & d1 & "#"
Else If kind="失访患者(登记时间)" Then
sql="select * from {基本情况} where 情况说明='无法联系'and 登记日期<#" & d2 & "# And 登记日期>#" & d1 & "#"
Else If kind="入院患者(入院日期)" Then
sql= "select * from {基本情况} where 情况说明='已入院'and 预约日期<#" & d2 & "# And 预约日期>#" & d1 & "#"
Else If kind="预约患者(入院日期)" Then
sql="select * from {基本情况} where (情况说明<>'推迟入院'or 情况说明<>'无法联系') and 预约日期<#" & d2 & "# And 预约日期>#" & d1 & "#"
End If
End If
End If
MessageBox.Show(d1,"提示")
MessageBox.Show(d2,"提示")
MessageBox.Show(kind,"提示")
MessageBox.Show(sql,"提示")
If t Then
Dim g As New GroupTableBuilder("统计表",sql)
g.Caption = "性别统计"
g.Groups.AddDef("性别", "", "性别")
g.Totals.AddDef("姓名", AggregateEnum.Count,"","病例数")
dts(i) = g.BuildDataSource()
End If
End If
Next
For i As Integer =1 To n-1
dts(0).Combine("性别",dts(i),"性别")
Next
forms("统计图形").Open
Tables("统计图形_Table1").DataSource = dts(0)