以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  找了半天,不知在哪加判断条件?请专家指点!  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=70187)

--  作者:zgjmost
--  发布时间:2015/6/17 8:54:00
--  找了半天,不知在哪加判断条件?请专家指点!

Dim js1 As Integer = Tables("选课数据表").Rows.Count

Forms("主界面").Open()
MainTable = Tables("主界面")

Dim dlg As new OpenFileDialog
dlg.Filter= "Excel文件|*.xls"
If dlg.ShowDialog = DialogResult.OK Then
    application.DoEvents
    Dim book  As new XLS.Book(dlg.FileName)
    Dim sheet1 As XLS.Sheet = book.Sheets(0)
    Dim bj,xh,xm,km As String
    StatusBar.Message1= "正在导入数据,请稍候"
    application.DoEvents
    If sheet1(2,0).text <> "试卷号" Then
        MessageBox.Show("您的数据源不符合国家开放大学报表平台的数据格式,不能导入学生信息表数据!", "提示")
    Else
        DataTables("选课数据表").StopRedraw
        For i As Integer = 1 To sheet1.Rows.count -1
            If sheet1(i,0).Text Like "班级*" Then
                Dim sts() As String = sheet1(i,0).Text.Split(" ")
                bj = sts(0).SubString(3)
                xh = sts(3).SubString(3)
                xm = sts(6).SubString(3)
                km = sheet1(i,5).text
            ElseIf  sheet1(i,0).text.Length = 4 Then
                Dim ksds As DataRow
                ksds = DataTables("选课数据表").AddNew()
                ksds("学号") = xh
                ksds("试卷号") = sheet1(i,0).text
                ksds("试卷名称") = sheet1(i,1).text
                ksds("考试类型") = sheet1(i,2).text
                ksds("考场号") = sheet1(i,3).text
                ksds("座位号") = sheet1(i,4).text
                ksds("日期") = sheet1(i,5).text
                ksds("时间") = sheet1(i,6).text
                ksds("是否留考") = sheet1(i,7).text
                ksds("是否排考") = "排考"
               
                Dim xhs As List(of String) = DataTables("学生信息表").GetValues("学号")
                If xhs.Contains(ksds("学号")) = False Then
                    ksds.Delete
                End If
            End If
            application.DoEvents
        Next
        DataTables("选课数据表").ResumeRedraw
    End If
End If

With Tables("选课数据表")
    For i As Integer = 0 To .Rows.Count - 1
        .Rows(i)("起始时间") = Left(.Rows(i)("时间"),5)
        .Rows(i)("结束时间") = Right(.Rows(i)("时间"),5)
        .Rows(i)("短日期") = Right(.Rows(i)("日期"),2) & "日"
    Next
End With

For Each r As Row In Tables("选课数据表").Rows
    Dim st As String = r("起始时间")
    If st.EndsWith("-") Then
        r("起始时间") = "0" & r("起始时间").trim("-")
    End If
Next

Tables("选课数据表").sort = "短日期,起始时间,考场号 desc,试卷号,座位号"

For Each r As Row In Tables("选课数据表").rows
    Dim dr1 As DataRow = DataTables("学生信息表").find("学号 = \'" & r("学号") & "\'")
    r("姓名") = dr1("姓名")
    r("班代码") = dr1("班代码")
    r("班名称") = dr1("班名称")
    r("班名称中文") = dr1("班名称中文")
    r("是否有照片") = dr1("是否有照片")
    r("学生类型") = dr1("学生类型")
    r("身份证号") = dr1("身份证号")
    r("性别") = dr1("性别")
Next

For Each dr As DataRow In DataTables("选课数据表").datarows
    dr("照片") = dr("身份证号") & ".jpg"
Next

Dim js2 As Integer = Tables("选课数据表").Rows.Count
Dim js3 As Integer = js2 - js1

For Each rr As Row In Tables("选课数据表").Rows
    Dim str1 As String = rr("起始时间")
    Dim str2 As String = rr("结束时间")
    Dim sp As TimeSpan = cdate("2000-1-1 " & str2) - cdate("2000-1-1 " & str1)
    Dim sp1 As String = sp.TotalMinutes
    rr("时长") = sp1
Next

Dim sts1 As String = DataTables("学生信息表").GetComboListString("学号","学籍状态 = \'毕业\'")
sts1 = "(\'" & sts1.Replace("|","\',\'") & "\')"
DataTables("选课数据表").ReplaceFor("是否排考","不排考","学号 in " & sts1)

StatusBar.Message1= "祝贺您!本次共成功导入" & js3 & "科次!"
MessageBox.Show("祝贺您!本次共成功导入" & js3 & "科次!")

Tables("选课数据表").filter = ""

StatusBar.Reset()

 

我执行这段代码时,当不选择Excel文件时,报下面的错:

 

 


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20150617085235.png
图片点击可在新窗口打开查看

找了半天,不知在哪加判断条件?请专家指点!


--  作者:Bin
--  发布时间:2015/6/17 8:55:00
--  
建议您用这个方法:
http://www.foxtable.com/help/topics/1485.htm

先找出是哪一行出错,然后分析原因,搞不定,可以在论坛发帖,贴出代码,并告诉我们运行到哪一行出错,以及错误提示。

--  作者:大红袍
--  发布时间:2015/6/17 9:09:00
--  

 不要delete啊,去掉代码啊

 

                Dim xhs As List(of String) = DataTables("学生信息表").GetValues("学号")
                If xhs.Contains(ksds("学号")) = False Then
                    ksds.Delete
                End If

 

 如果要判断,就在addNew的之前判断啊

 


--  作者:zgjmost
--  发布时间:2015/6/17 9:33:00
--  

For Each r As Row In Tables("选课数据表").rows
    Dim dr1 As DataRow = DataTables("学生信息表").find("学号 = \'" & r("学号") & "\'")
If dr1  Then

    r("姓名") = dr1("姓名")
    r("班代码") = dr1("班代码")
    r("班名称") = dr1("班名称")
    r("班名称中文") = dr1("班名称中文")
    r("是否有照片") = dr1("是否有照片")
    r("学生类型") = dr1("学生类型")
    r("身份证号") = dr1("身份证号")
    r("性别") = dr1("性别")
End If
Next

 

我估计是这个地方要加个判断,如果dr1存在,怎么表述?


--  作者:大红袍
--  发布时间:2015/6/17 9:40:00
--  
If dr1 IsNot Nothing Then