博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vb.net 浏览文件夹读取指定文件夹下的csv文件 并验证,显示错误信息
阅读量:5234 次
发布时间:2019-06-14

本文共 28627 字,大约阅读时间需要 95 分钟。

Imports System.Text

Imports Microsoft.VisualBasic.FileIO
Imports Shell32
Public Class Form1
    Protected Sub errorInfo(ByVal filePath As String)
        Dim csv()() As String
        Dim fs = Microsoft.VisualBasic.FileIO.FileSystem.GetFiles("D:\ALF_FILE\UPLOAD\Batch\data\", SearchOption.SearchTopLevelOnly, "*.csv")
        For Each fl In fs
            Dim fileName = fl.Substring(fl.LastIndexOf("\") + 1)
            Dim lines() As String = IO.File.ReadAllLines(fl, Encoding.GetEncoding("gb2312"))
            ReDim Preserve csv(lines.GetUpperBound(0) + 100)
            Dim csvHead() = lines(0).Split(","c)
            Dim errMasage = New StringBuilder()
            If fileName.StartsWith("D00") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧目名", csvHead))) Then
                        errMasage.Append("剧目名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("编剧", csvHead))) Then
                        errMasage.Append("编剧不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("编剧方式", csvHead))) Then
                        errMasage.Append("编剧方式不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("导演", csvHead))) Then
                        errMasage.Append("导演不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("主要演员", csvHead))) Then
                        errMasage.Append("主要演员不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        errMasage.Append("来源不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        errMasage.Append("剧种不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D01") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("题名", csvHead))) Then
                        errMasage.Append("题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("主讲人", csvHead))) Then
                        errMasage.Append("主讲人不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        errMasage.Append("来源不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D10") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧目名", csvHead))) Then
                        errMasage.Append("剧目名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("作词", csvHead))) Then
                        errMasage.Append("作词不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("演出者", csvHead))) Then
                        errMasage.Append("演出者不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        errMasage.Append("来源不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        errMasage.Append("剧种不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D11") Then
                errMasage = New StringBuilder()
                For x As Integer = 0 To lines.GetUpperBound(0)
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("题名", csvHead))) Then
                        errMasage.Append("题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("主讲人", csvHead))) Then
                        errMasage.Append("主讲人不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        errMasage.Append("来源不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D20") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("题名", csvHead))) Then
                        errMasage.Append("题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("主要人物", csvHead))) Then
                        errMasage.Append("主要人物不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        errMasage.Append("来源不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("来源", csvHead)).Equals("0") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("书(刊、资料)名", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页码", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版日期", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("分类号", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("网络名称", csvHead)))) Then
                                errMasage.Append("当剧种为原件复制的时候书(刊、资料)名、页码、出版单位、出版日期、分类号、网络名称必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("来源", csvHead)).Equals("1") Then
                            If (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("书(刊、资料)名", csvHead)))) _
                                 Or (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页码", csvHead)))) _
                                 Or (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead)))) _
                                 Or (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版日期", csvHead)))) Then
                                errMasage.Append("当剧种为原件复制的时候书(刊、资料)名、页码、出版单位、出版日期不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("网络名称", csvHead)))) Then
                                errMasage.Append("当剧种为来自书刊的时候网络名称必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("来源", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("书(刊、资料)名", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页码", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版日期", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("分类号", csvHead)))) Then
                                errMasage.Append("当剧种为原件复制的时候书(刊、资料)名、页码、出版单位、出版日期、分类号必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D21") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("题名", csvHead))) Then
                        errMasage.Append("题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        errMasage.Append("剧种不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        errMasage.Append("来源不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("来源", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("来源", csvHead)).Equals("0") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("书(刊、资料)名", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页码", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版日期", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("分类号", csvHead)))) _
                                Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("网络名称", csvHead)))) Then
                                errMasage.Append("当剧种为原件复制的时候书(刊、资料)名、页码、出版单位、出版日期、分类号、网络名称必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("来源", csvHead)).Equals("1") Then
                            If (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("书(刊、资料)名", csvHead)))) _
                                 Or (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页码", csvHead)))) _
                                 Or (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead)))) _
                                 Or (String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版日期", csvHead)))) Then
                                errMasage.Append("当剧种为原件复制的时候书(刊、资料)名、页码、出版单位、出版日期不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("网络名称", csvHead)))) Then
                                errMasage.Append("当剧种为来自书刊的时候网络名称必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("来源", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("书(刊、资料)名", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页码", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版日期", csvHead)))) _
                               Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("分类号", csvHead)))) Then
                                errMasage.Append("当剧种为原件复制的时候书(刊、资料)名、页码、出版单位、出版日期、分类号必须为空 ")
                            End If
                        End If
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D30") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("正题名", csvHead))) Then
                        errMasage.Append("正题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("著者名", csvHead))) Then
                        errMasage.Append("著者名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("著作方式", csvHead))) Then
                        errMasage.Append("著作方式不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页数", csvHead))) Then
                        errMasage.Append("页数不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead))) Then
                        errMasage.Append("出版单位不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版时间", csvHead))) Then
                        errMasage.Append("出版时间不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("分类号", csvHead))) Then
                        errMasage.Append("分类号不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("篇目类型", csvHead))) Then
                        errMasage.Append("篇目类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D31") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("正题名", csvHead))) Then
                        errMasage.Append("正题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("著者名", csvHead))) Then
                        errMasage.Append("著者名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("著作方式", csvHead))) Then
                        errMasage.Append("著作方式不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("页数", csvHead))) Then
                        errMasage.Append("页数不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版单位", csvHead))) Then
                        errMasage.Append("出版单位不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("出版时间", csvHead))) Then
                        errMasage.Append("出版时间不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("分类号", csvHead))) Then
                        errMasage.Append("分类号不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("篇目类型", csvHead))) Then
                        errMasage.Append("篇目类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        errMasage.Append("剧种不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D32") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("正题名", csvHead))) Then
                        errMasage.Append("正题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("作者", csvHead))) Then
                        errMasage.Append("作者不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        errMasage.Append("剧种不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
            If fileName.StartsWith("D33") Then
                For x As Integer = 0 To lines.GetUpperBound(0)
                    errMasage = New StringBuilder()
                    csv(x) = lines(x).Split(","c)
                    If csv(x)(csvIndex("资料类型", csvHead)) = "资料类型" Then
                        Continue For
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("文件名", csvHead))) Then
                        errMasage.Append("文件名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料类型", csvHead))) Then
                        errMasage.Append("资料类型不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("类别", csvHead))) Then
                        errMasage.Append("类别不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("正题名", csvHead))) Then
                        errMasage.Append("正题名不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("作者", csvHead))) Then
                        errMasage.Append("作者不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        errMasage.Append("剧种不能为空 ")
                    End If
                    If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("资料简介", csvHead))) Then
                        errMasage.Append("资料简介不能为空 ")
                    End If
                    If Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead))) Then
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("0") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead))) Then
                                errMasage.Append("当剧种为话剧的时候话剧不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为话剧的时候流派、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("1") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("2") Then
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead)))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候话剧、其他戏曲必须为空 ")
                            End If
                        End If
                        If csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("3") Or csv(x).ElementAtOrDefault(csvIndex("剧种", csvHead)).Equals("4") Then
                            If String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("其他戏曲", csvHead))) Then
                                errMasage.Append("当剧种为京剧或昆曲的时候其他戏曲不能为空 ")
                            End If
                            If (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("话剧", csvHead)))) Or (Not String.IsNullOrEmpty(csv(x).ElementAtOrDefault(csvIndex("流派", csvHead)))) Then
                                errMasage.Append("当剧种为地方戏或其他戏曲的时候话剧、流派必须为空 ")
                            End If
                        End If
                    End If
                    Call loadTab(errMasage.ToString, x, fl)
                Next
            End If
        Next
    End Sub
    Function csvIndex(ByVal cvsValue As String, ByVal csvHead() As String) As Integer
        Dim i = Array.IndexOf(csvHead, cvsValue)
        Return i
    End Function
    Private Sub loadTab(ByVal errMasage As String, ByVal x As Integer, ByVal fl As String)
        If Not String.IsNullOrEmpty(errMasage.ToString) Then
            Dim fileName = fl.Substring(fl.LastIndexOf("\") + 1)
            Dim errorMassage = New StringBuilder()
            errorMassage.Append("文件").Append(fileName).Append("第").Append(x).Append("行错误,").Append(errMasage)
            ListView1.Items.Add(errorMassage.ToString)
        End If
    End Sub
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim strId As String
        strId = Command()
        ListView1.Items.Clear()
        ListView1.Clear()
        ListView1.FullRowSelect = True
        ListView1.AllowColumnReorder = True     '对行进行程序排列,用鼠标进行排列
        ListView1.View = View.List
        ListView1.Items.Add("错误信息")
        ListView1.Items.Add("请选择验证文件")
        ListView1.Width = 1500
    End Sub
    Dim shlShell As Shell32.Shell
    Dim shlFolder As Shell32.Folder
    Private Const BIF_RETURNONLYFSDIRS = &H1
    Private Sub selectFoder_Click(sender As System.Object, e As System.EventArgs) Handles selectFoder.Click
        
        If shlShell Is Nothing Then
            shlShell = New Shell32.Shell
        End If
        shlFolder = shlShell.BrowseForFolder(0, "请选择文件夹", 0)
        If Not shlFolder Is Nothing Then
            TextBox1.Text = Trim(shlFolder.Items.Item.Path)
        End If
    End Sub
    Private Sub check_Click(sender As System.Object, e As System.EventArgs) Handles check.Click
        Call errorInfo(TextBox1.Text)
    End Sub
End Class

转载于:https://www.cnblogs.com/qshuwang/archive/2013/01/12/2857850.html

你可能感兴趣的文章
Python入门 五、学着机器思考
查看>>
js高级---本地对象、内置对象、宿主对象
查看>>
get与post请求
查看>>
基于反射技术汽车电子产品(ECU, SCM, 开关等)测试平台软件 (二)
查看>>
纪念日倒计时程序
查看>>
Python读取PDF文档
查看>>
leetcode-Game of Life-289
查看>>
(转)浅谈移动操作系统的跨应用通信机制
查看>>
常用的Hql语句
查看>>
可变字符串
查看>>
Postman
查看>>
事件的故事说明
查看>>
超大型 LED 显示屏
查看>>
poj 2342 Anniversary party_经典树状dp
查看>>
以后再也不写英文的文章了
查看>>
JS常用
查看>>
c# 怎么动态修改webservice的地址和端口 动态修改配置文
查看>>
usaco-5.1-theme-passed
查看>>
Android程序对不同手机屏幕分辨率自适应的总结
查看>>
分治法
查看>>