Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading
Imports Newtonsoft.Json
Imports UTS_Core.UTSModule
Imports UTS_Core.UTSModule.Project
Imports UTS_Core.UTSModule.Station

Public Class ProcessControlAPI

    Public g_API_Queue_List As Queue
    Public g_API_Queue_ResultList As List(Of QueueNode)
    Private g_API_index As Integer = 0
    Public Enum API_Type
        Allocation
        CombindSnInfo
        GetSnInfo
    End Enum
    Private _utsApp As UtsAppForm
    Sub New(utsApp As UtsAppForm)
        _utsApp = utsApp
        g_API_Queue_List = New Queue（）
        g_API_Queue_ResultList = New List(Of QueueNode)
        g_Thread = New Thread(AddressOf APIRuning)
    End Sub




#Region "线程相关"
    Private g_Thread As Thread

    Public Sub IsOprnThread(Isopen As Boolean)

        If Isopen Then

            If g_Thread.IsAlive Then Return     '已启动不管
            Try
                g_Thread.Abort()
                g_Thread = New Thread(AddressOf APIRuning)
                g_Thread.Start()    '未启动则启动
            Catch ex As Exception

            End Try

        Else
            If IsNothing(g_Thread) Then
                Return
            End If
            g_Thread.Abort()
        End If

    End Sub
    Public Sub APIRuning()
        Dim apiQueueNode As QueueNode
        Console.WriteLine($"{Date.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}:线程开始{vbCrLf }")
        While g_API_Queue_List.Count > 0
            apiQueueNode = CType(g_API_Queue_List.Dequeue, QueueNode)
            Console.WriteLine($"{Date.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}:对列处理中 id:{apiQueueNode.g_QueueID }{vbCrLf }")
            Select Case apiQueueNode.g_QueueType
                Case API_Type.Allocation
                    apiQueueNode.g_ResultObject = API_AllocationBarCode(apiQueueNode.g_Queuekey, apiQueueNode.g_QueueProjectID)
                Case API_Type.CombindSnInfo
                    apiQueueNode.g_ResultObject = API_Combind_Sn_Info(apiQueueNode.g_Queuekey, apiQueueNode.g_QueueProjectID, apiQueueNode.g_QueueDic)
                Case API_Type.GetSnInfo
                    apiQueueNode.g_ResultObject = API_Get_Sn_Info(apiQueueNode.g_Queuekey, apiQueueNode.g_QueueProjectID)
            End Select
            Console.WriteLine($"{Date.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}:对列已回复 id:{apiQueueNode.g_QueueID }{vbCrLf }")
            g_API_Queue_ResultList.Add(apiQueueNode)
            Thread.Sleep(10)
        End While
        Console.WriteLine($"{Date.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}:线程关闭{vbCrLf }")
    End Sub

#End Region
#Region "API"

    Public Function AutoIncrement() As Integer
        g_API_index = g_API_index + 1
        If g_API_index > 2000 Then
            g_API_index = 1
        End If
        Return g_API_index
    End Function
    ''' <summary>
    ''' SNCode 绑定 ColorCode
    ''' </summary>
    ''' <param name="snCode"></param>
    ''' <param name="ProjectID">项目id</param>
    ''' <param name="dbName">默认是 uts_zongqing</param>
    ''' <param name="pwd">默认是 actop00803</param>
    ''' <returns>成功返回对应信息，失败返回 Nothing </returns>
    Public Function API_AllocationBarCode(snCode As String, ProjectID As String， Optional dbName As String = "uts_zongqing", Optional pwd As String = "actop00803") As AllocationAPI
        Dim jsonString As String = String.Empty
        Try
            jsonString = PostData("http://uts-data.com/CommonApi/AllocationBarcode", $"Pwd={pwd}&Barcode={snCode}&DBName={dbName}&ProjectID={ProjectID}")
        Catch ex As Exception
            MsgBox($"网络API调用错误，请联系管理员。详情 ：http://uts-data.com/CommonApi/AllocationBarcode")
            Return Nothing
        End Try
        'Console.WriteLine(jsonString)

        If jsonString = Nothing Then
            Return Nothing
        End If

        Dim login As AllocationAPI = Nothing
        Try
            login = JsonConvert.DeserializeObject(Of AllocationAPI)(jsonString)
            If login.Status.ToLower.Equals("true") Then
                Return login
            Else
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox($"Json数据转换错误，请联系管理员。详情 ：Json data to AllocationAPI  error")
            Return Nothing
        End Try

    End Function
    ''' <summary>
    ''' SNCode 绑定 ColorCode
    ''' </summary>
    ''' <param name="snCode"></param>
    ''' <param name="ProjectID"></param>
    ''' <param name="dbName"></param>
    ''' <param name="pwd"></param>
    ''' <returns>返回对列节点中的序号，用于匹配节点</returns>
    Public Function API_Queue_AllocationBarCode(snCode As String, ProjectID As String， Optional dbName As String = "uts_zongqing", Optional pwd As String = "actop00803") As Integer
        Dim apiQueueNode As New QueueNode
        apiQueueNode.g_QueueID = AutoIncrement()
        apiQueueNode.g_QueueType = API_Type.Allocation

        apiQueueNode.g_QueueProjectID = ProjectID
        apiQueueNode.g_Queuekey = snCode
        apiQueueNode.G_dbname = dbName
        apiQueueNode.g_pwd = pwd
        g_API_Queue_List.Enqueue(apiQueueNode)
        IsOprnThread(True)
        Return apiQueueNode.g_QueueID
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="ColumnName">查询 索引 的 列名 </param>
    ''' <param name="ProjectID">项目id</param>
    ''' <param name="dic">查询与写入 的 关键字 与内容 </param>
    ''' <param name="dbName">默认 uts_zongqing</param>
    ''' <param name="pwd">默认 actop00803</param>
    ''' <returns></returns>
    Public Function API_Combind_Sn_Info(ColumnName As String, ProjectID As String， dic As Dictionary(Of String, String）， Optional dbName As String = "uts_zongqing", Optional pwd As String = "actop00803") As CombindSnInfo
        Dim jsonString As String = String.Empty
        Try
            Dim ptr As String = $"Pwd={pwd}&DBName={dbName}&Key={ColumnName}"
            If Not IsNothing（dic） Then
                ptr = ptr & $"&JsonData={JsonConvert.SerializeObject(dic)}"
            End If
            ptr = ptr & $"&ProjectID={ProjectID}"
            jsonString = PostData("http://uts-data.com/CommonApi/Combind_Sn_Info", ptr)

        Catch ex As Exception
            MsgBox($"网络API调用错误，请联系管理员。详情 ：http://uts-data.com/CommonApi/AllocationBarcode")
            Return Nothing
        End Try
        'Console.WriteLine(jsonString)

        If jsonString = Nothing Then
            Return Nothing
        End If

        Dim login As New CombindSnInfo
        Try
            login = JsonConvert.DeserializeObject(Of CombindSnInfo)(jsonString)
            If login.State.ToLower.Equals("true") Then
                Return login
            Else
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox($"Json数据转换错误，请联系管理员。详情 ：Json data to AllocationAPI  error")
            Return Nothing
        End Try


    End Function
    Public Function API_Queue_Combind_Sn_Info(ColumnName As String, ProjectID As String， dic As Dictionary(Of String, String）， Optional dbName As String = "uts_zongqing", Optional pwd As String = "actop00803") As Integer
        Dim apiQueueNode As New QueueNode
        apiQueueNode.g_QueueID = AutoIncrement()
        apiQueueNode.g_QueueType = API_Type.CombindSnInfo

        apiQueueNode.g_QueueProjectID = ProjectID
        apiQueueNode.g_Queuekey = ColumnName
        apiQueueNode.g_QueueDic = dic
        apiQueueNode.G_dbname = dbName
        apiQueueNode.g_pwd = pwd

        g_API_Queue_List.Enqueue(apiQueueNode)
        IsOprnThread(True)
        Return apiQueueNode.g_QueueID
    End Function

    Public Function API_Get_Sn_Info(ColumnVal As String, ProjectID As String， Optional dbName As String = "uts_zongqing", Optional pwd As String = "actop00803") As CombindSnInfo
        Dim jsonString As String = String.Empty
        Try
            Dim ptr As String = $"Pwd={pwd}&DBName={dbName}&Key={ColumnVal}&ProjectID={ProjectID}"
            jsonString = PostData("http://uts-data.com/CommonApi/Get_Sn_Info", ptr)
            If jsonString = Nothing Then
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox($"网络API调用错误，请联系管理员。详情 ：http://uts-data.com/CommonApi/AllocationBarcode")
            Return Nothing
        End Try
        Dim login As New CombindSnInfo
        Try
            login = JsonConvert.DeserializeObject(Of CombindSnInfo)(jsonString)
            If login.State.ToLower.Equals("true") Then
                Return login
            Else
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox($"Json数据转换错误，请联系管理员。详情 ：Json data to AllocationAPI  error")
            Return Nothing
        End Try


    End Function
    Public Function API_Queue_Get_Sn_Info(ColumnVal As String, ProjectID As String， Optional dbName As String = "uts_zongqing", Optional pwd As String = "actop00803") As Integer
        Dim apiQueueNode As New QueueNode
        apiQueueNode.g_QueueID = AutoIncrement()
        apiQueueNode.g_QueueType = API_Type.GetSnInfo

        apiQueueNode.g_QueueProjectID = ProjectID
        apiQueueNode.g_Queuekey = ColumnVal
        ' apiQueueNode.g_QueueDic = dic
        apiQueueNode.G_dbname = dbName
        apiQueueNode.g_pwd = pwd
        g_API_Queue_List.Enqueue(apiQueueNode)
        IsOprnThread(True)
        Return apiQueueNode.g_QueueID
    End Function


    ''' <summary>
    ''' POST 数据获取
    ''' </summary>
    ''' <param name="url">访问地址</param>
    ''' <param name="data">访问参数</param>
    ''' <returns></returns>
    Public Shared Function PostData(ByVal url As String, ByVal data As String) As String

        ServicePointManager.Expect100Continue = False
        Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
        '//Post请求方式
        request.Method = "POST"

        '内容类型
        request.ContentType = "application/x-www-form-urlencoded"
        '将URL编码后的字符串转化为字节
        Dim encoding As New UTF8Encoding()
        Dim bys As Byte() = encoding.GetBytes(data)
        '设置请求的 ContentLength 
        request.ContentLength = bys.Length
        '获得请 求流
        Dim newStream As Stream = request.GetRequestStream()
        newStream.Write(bys, 0, bys.Length)
        newStream.Close()
        '获得响应流
        Dim sr As StreamReader = New StreamReader(request.GetResponse().GetResponseStream)
        Return sr.ReadToEnd
    End Function


#End Region


#Region "站位控制"

    '检测本站前所有站是否测试
    Public Function IsALLStation(station As String, macstr As String) As Boolean
        ' If Not _isStartUsing Then Return True
        Dim macconfig As CombindSnInfo = API_Get_Sn_Info(macstr, _utsApp.ProcessStation.ParentProject.Index.ToString)
        Dim msstring As String = ""
        Dim asd As String = ""
        If IsNothing(macconfig) Then Return False
        If station.Equals("T1") Then
            Return True
        ElseIf station.Equals("T2") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T1")
                MsgBox($"T1:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T3") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If
                MsgBox(msstring)
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T4") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If
                MsgBox(msstring)
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T5") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If

                MsgBox(msstring)

                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T6") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                MsgBox(msstring)
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P1") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T6")
                    msstring = msstring & $"T6:{asd} 未测试." & vbCrLf
                End If
                MsgBox(msstring)

                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P2") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T6")
                    msstring = msstring & $"T6:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P1")
                    msstring = msstring & $"P1:{asd} 未测试." & vbCrLf
                End If

                MsgBox(msstring)

                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P3") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T6")
                    msstring = msstring & $"T6:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P1")
                    msstring = msstring & $"P1:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P2")
                    msstring = msstring & $"P2:{asd} 未测试." & vbCrLf
                End If


                MsgBox(msstring)

                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P4") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T6")
                    msstring = msstring & $"T6:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P1")
                    msstring = msstring & $"P1:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P2")
                    msstring = msstring & $"P2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P3")
                    msstring = msstring & $"P3:{asd} 未测试." & vbCrLf
                End If

                MsgBox(msstring)

                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P5") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT10") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT10")) OrElse macconfig.data.Item("RESULT10").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T6")
                    msstring = msstring & $"T6:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P1")
                    msstring = msstring & $"P1:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P2")
                    msstring = msstring & $"P2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P3")
                    msstring = msstring & $"P3:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT10") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT10")) OrElse macconfig.data.Item("RESULT10").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P4")
                    msstring = msstring & $"P4:{asd} 未测试." & vbCrLf
                End If
                MsgBox(msstring)
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P6") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") OrElse
                 IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") OrElse
               IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT10") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT10")) OrElse macconfig.data.Item("RESULT10").Equals("0") OrElse
                IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT11") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT11")) OrElse macconfig.data.Item("RESULT11").Equals("0") Then

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T1")
                    msstring = msstring & $"T1:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T2")
                    msstring = msstring & $"T2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T3")
                    msstring = $"T3:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T4")
                    msstring = $"T4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T5")
                    msstring = msstring & $"T5:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("T6")
                    msstring = msstring & $"T6:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P1")
                    msstring = msstring & $"P1:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P2")
                    msstring = msstring & $"P2:{asd} 未测试." & vbCrLf
                End If

                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P3")
                    msstring = msstring & $"P3:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT10") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT10")) OrElse macconfig.data.Item("RESULT10").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P4")
                    msstring = msstring & $"P4:{asd} 未测试." & vbCrLf
                End If
                If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT11") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT11")) OrElse macconfig.data.Item("RESULT11").Equals("0") Then
                    asd = CboProject_SelectedIndexChanged("P5")
                    msstring = msstring & $"P5:{asd} 未测试." & vbCrLf
                End If

                MsgBox(msstring)

                Return False
            Else
                Return True
            End If
        End If
    End Function

    ''' <summary>
    ''' 待完善
    ''' </summary>
    ''' <param name="stationId"></param>
    ''' <param name="macstr"></param>
    ''' <returns></returns>
    Public Function IsALLStation(stationId As Integer, macstr As String) As Boolean
        Dim isResult As Boolean = True
        Dim d_mesg As String = ""
        Dim macconfig As CombindSnInfo = API_Get_Sn_Info(macstr, _utsApp.ProcessStation.ParentProject.Index.ToString)
        If IsNothing(macconfig) OrElse IsNothing(macconfig.data) OrElse stationId < 1 Then
            MsgBox("未获取到该产品测试信息，请联系开发者")
            Return False
        End If
        For intindex As Integer = 1 To stationId - 1
            If Not macconfig.data.ContainsKey($"RESULT{intindex}") OrElse String.IsNullOrEmpty(macconfig.data.Item($"RESULT{intindex}")) OrElse macconfig.data.Item($"RESULT{intindex}").Equals("0") Then
                d_mesg = d_mesg & CboProject_SelectedIndexChanged1(intindex)
                'MsgBox($"T1:{msstring} 未测试.")
                isResult = False
            End If
        Next
        If Not String.IsNullOrEmpty(d_mesg) Then
            MsgBox($"{d_mesg}")
        End If
        Return isResult
    End Function


    '检测前一站是否测试
    Public Function IsFrontStation(station As String, macstr As String) As Boolean
        Dim macconfig As CombindSnInfo = API_Get_Sn_Info(macstr, _utsApp.ProcessStation.ParentProject.Index.ToString)
        Dim msstring As String = ""
        If IsNothing(macconfig) Then Return False
        If station.Equals("T1") Then
            Return True
        ElseIf station.Equals("T2") Then
            Return True
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT1") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT1")) OrElse macconfig.data.Item("RESULT1").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T1")
                MsgBox($"T1:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T3") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT2") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT2")) OrElse macconfig.data.Item("RESULT2").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T2")
                MsgBox($"T2:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T4") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT3") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT3")) OrElse macconfig.data.Item("RESULT3").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T3")
                MsgBox($"T3:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T5") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT4") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT4")) OrElse macconfig.data.Item("RESULT4").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T4")
                MsgBox($"T4:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("T6") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT5") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT5")) OrElse macconfig.data.Item("RESULT5").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T5")
                MsgBox($"T5:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P1") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT6") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT6")) OrElse macconfig.data.Item("RESULT6").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("T6")
                MsgBox($"T6:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P2") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT7") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT7")) OrElse macconfig.data.Item("RESULT7").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("P1")
                MsgBox($"P1:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P3") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT8") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT8")) OrElse macconfig.data.Item("RESULT8").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("P2")
                MsgBox($"P2:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P4") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT9") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT9")) OrElse macconfig.data.Item("RESULT9").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("P3")
                MsgBox($"P3:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P5") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT10") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT10")) OrElse macconfig.data.Item("RESULT10").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("P4")
                MsgBox($"P4:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        ElseIf station.Equals("P6") Then
            If IsNothing(macconfig.data) OrElse Not macconfig.data.ContainsKey("RESULT11") OrElse String.IsNullOrEmpty(macconfig.data.Item("RESULT11")) OrElse macconfig.data.Item("RESULT11").Equals("0") Then
                msstring = CboProject_SelectedIndexChanged("P5")
                MsgBox($"P5:{msstring} 未测试.")
                Return False
            Else
                Return True
            End If
        End If
    End Function
    Public Function IsFrontStation(stationId As Integer, macstr As String) As Boolean
        Dim isResult As Boolean = True
        Dim d_mesg As String = ""

        Dim macconfig As CombindSnInfo = API_Get_Sn_Info(macstr, _utsApp.ProcessStation.ParentProject.Index.ToString)
        If IsNothing(macconfig) OrElse IsNothing(macconfig.data) OrElse stationId < 1 Then
            MsgBox("未获取到该产品测试信息，请联系开发者")
            Return False
        End If
        If stationId = 1 Then Return True
        Dim upstation As Integer = stationId - 1
        If Not macconfig.data.ContainsKey($"RESULT{upstation}") OrElse String.IsNullOrEmpty(macconfig.data.Item($"RESULT{upstation}")) OrElse macconfig.data.Item($"RESULT{upstation}").Equals("0") Then
            d_mesg = d_mesg & CboProject_SelectedIndexChanged1(upstation)
            MsgBox($"{d_mesg}")
            isResult = False
        End If

        Return isResult
    End Function

    Private Function CboProject_SelectedIndexChanged(thestation As String) As String
        Dim projectInfo As New ProjectInfo(_utsApp.Account.UserId, _utsApp.ProcessStation.ParentProject.Name, ProjectInfo.InitializeModeEnum.LocalDatabaseLoad)

        If IsNothing(projectInfo) Then
            Return "站位信息异常请联系开发者！"
        End If

        For Each station As ProcessStation In projectInfo.Station
            If station.Name.Trim.Equals(thestation.Trim) Then
                Return station.Description
            End If
        Next

        Return "未找到该站位描述."
        ' UpdateProjectStation(_projectInfo.Station)
    End Function

    Private Function CboProject_SelectedIndexChanged1(thestationid As Integer) As String
        Dim projectInfo As New ProjectInfo(_utsApp.Account.UserId, _utsApp.ProcessStation.ParentProject.Name, ProjectInfo.InitializeModeEnum.LocalDatabaseLoad)

        If IsNothing(projectInfo) Then
            Return "站位信息异常请联系开发者！"
        End If

        For Each station As ProcessStation In projectInfo.Station
            If station.SnListOrder = thestationid Then
                Return $"{station.Name.Trim}:{station.Description}未测试.{vbCrLf }"
            End If
        Next

        Return "未找到该站位描述."
        ' UpdateProjectStation(_projectInfo.Station)
    End Function
    '本站置位
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="thestation">站名</param>
    ''' <param name="macstr">Dut_sn</param>
    ''' <param name="isok">测试标记  0-1</param>
    Public Sub SetStationflag(thestationid As Integer, macstr As String, isok As String, Optional ndic As Dictionary(Of String, String) = Nothing)

        Dim dic As New Dictionary(Of String, String)

        dic.Add("Barcode"， macstr)
        dic.Add($"RESULT{thestationid}"， isok)
        dic.Add($"S{thestationid}"， $"{Now:yyyy-MM-dd HH:mm:ss}")


        'If thestation.Equals("T1") Then
        '    dic.Add("RESULT1"， isok)
        '    dic.Add("S1"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("T2") Then
        '    dic.Add("RESULT1"， isok)
        '    dic.Add("S2"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("T3") Then
        '    dic.Add("RESULT3"， isok)
        '    dic.Add("S3"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("T4") Then
        '    dic.Add("RESULT4"， isok)
        '    dic.Add("S4"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("T5") Then
        '    dic.Add("RESULT5"， isok)
        '    dic.Add("S5"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("T6") Then
        '    dic.Add("RESULT6"， isok)
        '    dic.Add("S6"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("P1") Then
        '    dic.Add("RESULT7"， isok)
        '    dic.Add("S7"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("P2") Then
        '    dic.Add("RESULT8"， isok)
        '    dic.Add("S8"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("P3") Then
        '    dic.Add("RESULT9"， isok)
        '    dic.Add("S9"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("P4") Then
        '    dic.Add("RESULT10"， isok)
        '    dic.Add("S10"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("P5") Then
        '    dic.Add("RESULT11"， isok)
        '    dic.Add("S11"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'ElseIf thestation.Equals("P6") Then
        '    dic.Add("RESULT12"， isok)
        '    dic.Add("S12"， $"{Now:yyyy-MM-dd HH:mm:ss}")
        'End If


        API_Queue_Combind_Sn_Info("Barcode", _utsApp.ProcessStation.ParentProject.Index.ToString, dic)


    End Sub

#End Region




End Class
''' <summary>
''' SN_Code 绑定 ColorCode 专属类
''' </summary>
Public Class AllocationAPI
    Sub New()

    End Sub

    Public Mars_ColorBox_BarCode As String
    Public Message As String
    Public Barcodeas As String
    Public Status As String

End Class
''' <summary>
''' CombindSnInfo API读写数据库 返回内容装载类
''' </summary>
Public Class CombindSnInfo
    Sub New()
        data = New Dictionary(Of String, String)
    End Sub

    Public data As Dictionary(Of String, String）
    Public Message As String
    Public State As String
End Class



Public Class QueueNode

    ''' <summary>
    ''' 电子秤读回数据单位枚举
    ''' </summary>

    Sub New()

    End Sub
    '唯一标识 序号
    Public g_QueueID As Integer

    'API类型
    Public g_QueueType As Integer

    'API所需参数
    Public g_QueueDic As Dictionary(Of String, String）
    Public g_QueueProjectID As String
    Public g_Queuekey As String
    Public g_pwd As String
    Public G_dbname As String

    'API返回结果
    Public g_ResultObject As Object
End Class







'队列（Queue）

'队列代表一个先进先出的集合

'队列元素为Object类型

'.net框架提供Queue<T>泛型队列类

'　　入队（Enqueue)和出队(Dequeue)是对列的基本操作，入队入队尾，出队出队头。

'　　继承接口：IEnumerable,ICollections,ICloneable



'常用方法和属性：

'　　void Enqueue(object obj)　　//入队，入队尾

'　　object Dequeue()　　//出队，出队头，并返回出队对象

'　　object Peek()　　//查看队头元素

'　　bool Contains(object obj)　　//是否包含元素obj

'　　void Clear()　　//清除所有元素

'　　object[] ToArray()　　//元素复制到新数组