Dim str1 As String
str1 = "select cuscoursename as 课程名,sum(case custype when '迟到' then 1 else 0 end) as 迟到,sum(case custype when '早退' then 1 else 0 end) as 早退,sum(case custype when '旷课' then 1 else 0 end) as 旷课,sum(case custype when '请假' then 1 else 0 end) as 请假,sum(case custype when '无违纪' then 1 else 0 end) as 无违纪 from course " & coursetiaojian & " group by cuscoursename "
Dim conn As New OleDbConnection(glinkstring)
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Try
conn.Open()
da = New OleDbDataAdapter(str1, conn)
' MessageBox.Show(str1)
da.Fill(ds, "jiaochabiao")
'MessageBox.Show("ok")
da.Dispose()
conn.Dispose()
Catch ex As Exception
conn.Dispose()
MessageBox.Show(Err.Description)
End Try
'构建最终数据表
Dim tb As New DataTable("ketang")
Dim col As New DataColumn("chuqinlv")
col.DataType = System.Type.GetType("System.Decimal")
tb.Columns.Add(col)
col = New DataColumn("coursename")
tb.Columns.Add(col)
'处理交叉表中的数据,填充到最终数据表中
Dim ttb As New DataTable
ttb = ds.Tables("jiaochabiao")
Dim i As Integer, j As Single = 0.0
Dim x As Integer, y As Integer
For i = 0 To ttb.Rows.Count - 1
x = ttb.Rows(i).Item("旷课") + ttb.Rows(i).Item("请假")
y = ttb.Rows(i).Item("迟到") + ttb.Rows(i).Item("旷课") + ttb.Rows(i).Item("请假") + ttb.Rows(i).Item("早退") + ttb.Rows(i).Item("无违纪")
j = (y - x) / y
Dim r As DataRow
r = tb.NewRow
r.Item(1) = ttb.Rows(i).Item(0)
' MessageBox.Show(j)
r.Item(0) = j
tb.Rows.Add(r)
Next
Dim coursename As New jitireport1
'coursename.SetDataSource(tb)
'打开报表窗体
Dim viewer As New jitireport1
viewer.Show()
' MessageBox.Show("ok")
viewer.initereports(tb, ds)