Imports iMESExceptionManager

Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Public Class frmTestData21681

    Inherits COM_Kit.frmBasisTemplat

    Public PrivFunNo As String = defString

    '//WS相關變數
    ' 2016 YF, Dim wsENT As New wsENT.wsENT   '宣告Web Service物件?
    Dim tmpStringReader As System.IO.StringReader '將字串轉換成可讀入DataSet的物件
    Dim XmlData As String '儲存取回之資料
    Dim XmlSchema As String '儲存取回之資料結構
    Dim InXml As String '儲存呼叫Web Service的傳入參數(Request字串)
    Dim OutXml As String '儲存Web Service的傳回值(Response字串)
    Dim strIdentity As String '儲存Identity XML字串?
    Dim strParameter As String '儲存Parameter XML字串

    '//資料表相關變數

    Dim dsENT As New DataSet   '資料集：儲存取回之資料?

    Dim tblENTSubcontractor As String '儲存取回資料表的名稱(master)?
    Dim tblENTSubcontractorCont As String   '明細資料表名稱(detail)
    Dim strFilter As String   'Filter string及列印的過濾條件

    '//其他共用變數
    Dim SubcontractorNo As String 'for Gird to Focus
    Dim ContactorName As String 'for DetailGrid to Focus
    Dim ugrRow As Infragistics.Win.UltraWinGrid.UltraGridRow
    Friend WithEvents btnAdd As Misc.UltraButton
    Friend WithEvents btnEdit As Misc.UltraButton
    Friend WithEvents btnDel As Misc.UltraButton
    Friend WithEvents btnCopy As Misc.UltraButton
    Friend WithEvents btnApprove As Misc.UltraButton
    Friend WithEvents iugSubcontractor As iMESUltraGrid.iMESUltraGridControl
    Dim i As Integer

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container
    Friend WithEvents iugDetail As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents btnClose As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnEMail As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnDCopy As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnDDel As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnDEdit As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnDAdd As Infragistics.Win.Misc.UltraButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnClose = New Infragistics.Win.Misc.UltraButton()
        Me.btnEMail = New Infragistics.Win.Misc.UltraButton()
        Me.btnDCopy = New Infragistics.Win.Misc.UltraButton()
        Me.btnDDel = New Infragistics.Win.Misc.UltraButton()
        Me.btnDEdit = New Infragistics.Win.Misc.UltraButton()
        Me.btnDAdd = New Infragistics.Win.Misc.UltraButton()
        Me.iugDetail = New iMESUltraGrid.iMESUltraGridControl()
        Me.btnAdd = New Infragistics.Win.Misc.UltraButton()
        Me.btnEdit = New Infragistics.Win.Misc.UltraButton()
        Me.btnDel = New Infragistics.Win.Misc.UltraButton()
        Me.btnCopy = New Infragistics.Win.Misc.UltraButton()
        Me.btnApprove = New Infragistics.Win.Misc.UltraButton()
        Me.iugSubcontractor = New iMESUltraGrid.iMESUltraGridControl()
        Me.SuspendLayout()
        '
        'btnClose
        '
        Me.btnClose.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnClose.Location = New System.Drawing.Point(912, 552)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(88, 32)
        Me.btnClose.TabIndex = 18
        Me.btnClose.Text = "Close (&X)"
        '
        'btnEMail
        '
        Me.btnEMail.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnEMail.Location = New System.Drawing.Point(912, 429)
        Me.btnEMail.Name = "btnEMail"
        Me.btnEMail.Size = New System.Drawing.Size(88, 32)
        Me.btnEMail.TabIndex = 17
        Me.btnEMail.Text = "Mail"
        '
        'btnDCopy
        '
        Me.btnDCopy.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDCopy.Location = New System.Drawing.Point(912, 389)
        Me.btnDCopy.Name = "btnDCopy"
        Me.btnDCopy.Size = New System.Drawing.Size(88, 32)
        Me.btnDCopy.TabIndex = 16
        Me.btnDCopy.Text = "Copy"
        '
        'btnDDel
        '
        Me.btnDDel.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDDel.Location = New System.Drawing.Point(912, 349)
        Me.btnDDel.Name = "btnDDel"
        Me.btnDDel.Size = New System.Drawing.Size(88, 32)
        Me.btnDDel.TabIndex = 15
        Me.btnDDel.Text = "DEL"
        '
        'btnDEdit
        '
        Me.btnDEdit.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDEdit.Location = New System.Drawing.Point(912, 309)
        Me.btnDEdit.Name = "btnDEdit"
        Me.btnDEdit.Size = New System.Drawing.Size(88, 32)
        Me.btnDEdit.TabIndex = 14
        Me.btnDEdit.Text = "EDIT"
        '
        'btnDAdd
        '
        Me.btnDAdd.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDAdd.Location = New System.Drawing.Point(912, 269)
        Me.btnDAdd.Name = "btnDAdd"
        Me.btnDAdd.Size = New System.Drawing.Size(88, 32)
        Me.btnDAdd.TabIndex = 13
        Me.btnDAdd.Text = "ADD"
        '
        'iugDetail
        '
        Me.iugDetail.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
            Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.iugDetail.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugDetail.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugDetail.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugDetail.Identity = "IMes"
        Me.iugDetail.IdentityForm = ""
        Me.iugDetail.LayOutFilePath = ""
        Me.iugDetail.Location = New System.Drawing.Point(12, 270)
        Me.iugDetail.Name = "iugDetail"
        Me.iugDetail.PrintFitWidthToPages = 0
        Me.iugDetail.PrintLandscape = True
        Me.iugDetail.PrintPageFooter = ""
        Me.iugDetail.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugDetail.PrintPageFooterHeight = 20
        Me.iugDetail.PrintPageHeader = ""
        Me.iugDetail.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugDetail.PrintPageHeaderHeight = 20
        Me.iugDetail.PrintZoom = 1.0R
        Me.iugDetail.Size = New System.Drawing.Size(894, 314)
        Me.iugDetail.TabIndex = 12
        Me.iugDetail.UserNo = "IMes"
        '
        'btnAdd
        '
        Me.btnAdd.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnAdd.Location = New System.Drawing.Point(912, 53)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(88, 32)
        Me.btnAdd.TabIndex = 20
        Me.btnAdd.Text = "Add(&A)"
        '
        'btnEdit
        '
        Me.btnEdit.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnEdit.Location = New System.Drawing.Point(912, 93)
        Me.btnEdit.Name = "btnEdit"
        Me.btnEdit.Size = New System.Drawing.Size(88, 32)
        Me.btnEdit.TabIndex = 21
        Me.btnEdit.Text = "Edit(&E)"
        '
        'btnDel
        '
        Me.btnDel.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDel.Location = New System.Drawing.Point(912, 133)
        Me.btnDel.Name = "btnDel"
        Me.btnDel.Size = New System.Drawing.Size(88, 32)
        Me.btnDel.TabIndex = 22
        Me.btnDel.Text = "Del(&D)"
        '
        'btnCopy
        '
        Me.btnCopy.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnCopy.Location = New System.Drawing.Point(912, 173)
        Me.btnCopy.Name = "btnCopy"
        Me.btnCopy.Size = New System.Drawing.Size(88, 32)
        Me.btnCopy.TabIndex = 23
        Me.btnCopy.Text = "Copy(&C)"
        '
        'btnApprove
        '
        Me.btnApprove.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnApprove.Location = New System.Drawing.Point(912, 213)
        Me.btnApprove.Name = "btnApprove"
        Me.btnApprove.Size = New System.Drawing.Size(88, 32)
        Me.btnApprove.TabIndex = 24
        Me.btnApprove.Text = "Approve(&Y)"
        '
        'iugSubcontractor
        '
        Me.iugSubcontractor.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
            Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.iugSubcontractor.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugSubcontractor.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugSubcontractor.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugSubcontractor.Identity = "IMes"
        Me.iugSubcontractor.IdentityForm = ""
        Me.iugSubcontractor.LayOutFilePath = ""
        Me.iugSubcontractor.Location = New System.Drawing.Point(12, 53)
        Me.iugSubcontractor.Name = "iugSubcontractor"
        Me.iugSubcontractor.PrintFitWidthToPages = 0
        Me.iugSubcontractor.PrintLandscape = True
        Me.iugSubcontractor.PrintPageFooter = ""
        Me.iugSubcontractor.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugSubcontractor.PrintPageFooterHeight = 20
        Me.iugSubcontractor.PrintPageHeader = ""
        Me.iugSubcontractor.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugSubcontractor.PrintPageHeaderHeight = 20
        Me.iugSubcontractor.PrintZoom = 1.0R
        Me.iugSubcontractor.Size = New System.Drawing.Size(894, 192)
        Me.iugSubcontractor.TabIndex = 25
        Me.iugSubcontractor.UserNo = "IMes"
        '
        'frmSubcontractor
        '
        Me.ClientSize = New System.Drawing.Size(1008, 591)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.btnApprove)
        Me.Controls.Add(Me.btnEMail)
        Me.Controls.Add(Me.btnDCopy)
        Me.Controls.Add(Me.btnCopy)
        Me.Controls.Add(Me.btnDDel)
        Me.Controls.Add(Me.iugSubcontractor)
        Me.Controls.Add(Me.btnDEdit)
        Me.Controls.Add(Me.btnAdd)
        Me.Controls.Add(Me.btnDAdd)
        Me.Controls.Add(Me.btnDel)
        Me.Controls.Add(Me.iugDetail)
        Me.Controls.Add(Me.btnEdit)
        Me.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "frmSubcontractor"
        Me.Text = "ENT Subcontractor & Contactor"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        Me.Controls.SetChildIndex(Me.btnEdit, 0)
        Me.Controls.SetChildIndex(Me.iugDetail, 0)
        Me.Controls.SetChildIndex(Me.btnDel, 0)
        Me.Controls.SetChildIndex(Me.btnDAdd, 0)
        Me.Controls.SetChildIndex(Me.btnAdd, 0)
        Me.Controls.SetChildIndex(Me.btnDEdit, 0)
        Me.Controls.SetChildIndex(Me.iugSubcontractor, 0)
        Me.Controls.SetChildIndex(Me.btnDDel, 0)
        Me.Controls.SetChildIndex(Me.btnCopy, 0)
        Me.Controls.SetChildIndex(Me.btnDCopy, 0)
        Me.Controls.SetChildIndex(Me.btnEMail, 0)
        Me.Controls.SetChildIndex(Me.btnApprove, 0)
        Me.Controls.SetChildIndex(Me.btnClose, 0)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmSubcontractor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Cursor.Current = Cursors.WaitCursor

        ' 2016 YF, wsENT.Url = LocalizeWebService(wsENT.Url.ToString)
        ' 2016 YF, wsENT.EnableDecompression = True

        Call funiMESUltraGridIni() 'Grid初始設定

        '//取出資料
        Call funLoadSubcontractor()

        SetIssueState(Issue.Unfrozen)   '預設在Unforzen上
        SetSearchFieldName(New String() {"SubcontractorNo", "SubcontractorNaME"})     '設置搜尋欄位


        '語系切換
        Call ExeChangeResource(Me, gLanguageMode)
        ExeGroupControlPriv(Me, PrivFunNo)

        Cursor.Current = Cursors.Default

    End Sub

    Private Sub frmSubcontractor_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If Not dsENT Is Nothing Then dsENT.Dispose()
        ' 2016 YF, If Not wsENT Is Nothing Then wsENT.Dispose()
    End Sub

    Protected Overrides Sub rdoIssue_CheckedChanged(sender As Object, e As EventArgs)
        If IsNothing(dsENT) Then Exit Sub

        Select Case GetIssueState()
            Case Issue.Unfrozen
                dsENT.Tables(tblENTSubcontractor).DefaultView.RowFilter = "IssueState=0"
            Case Issue.Pending
                dsENT.Tables(tblENTSubcontractor).DefaultView.RowFilter = "IssueState=1"
            Case Issue.Active
                dsENT.Tables(tblENTSubcontractor).DefaultView.RowFilter = "IssueState=2"
            Case Issue.Unused
                dsENT.Tables(tblENTSubcontractor).DefaultView.RowFilter = "IssueState=-1"
        End Select
        Me.iugSubcontractor.iMESUltraGrid.DataSource = dsENT.Tables(tblENTSubcontractor).DefaultView
        Call funShowActiveDetail()
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim fSubcontractorDef As New frmTestData21681Def

        fSubcontractorDef.DefMode = 0
        fSubcontractorDef.ShowDialog(Me)
        fSubcontractorDef.Dispose()

        If gReturnKeyValue = "" Then Exit Sub

        SubcontractorNo = gReturnKeyValue

        '重新取出資料
        Call funLoadSubcontractor()

        If GetIssueState() = Issue.Unfrozen Then
            ugrRow = FindRecordPosition(iugSubcontractor, "SubcontractorNo", SubcontractorNo)
            If Not ugrRow Is Nothing Then
                Me.iugSubcontractor.iMESUltraGrid.ActiveRow = ugrRow
                Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected = True
            End If
        End If

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click



        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing Then
            'IsGroupByRow不做任何處理
            If iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow Then
                Exit Sub
            End If
            Dim Rows As DataRow()

            '找出DataSet中在目前游標列的資料列(DataRow)
            Rows = dsENT.Tables(tblENTSubcontractor).Select("SubcontractorNo = '" _
                & Replace(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString, "'", "''") & "'")

            '核准狀態為"Unfrozen"者才可修改

            If Rows(0).Item("IssueState") <> 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202202", "[%NOT ALLOWED TO EDIT%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If

            Dim fSubcontractorDef As New frmTestData21681Def
            fSubcontractorDef.DefMode = 1
            fSubcontractorDef.EditDataRow = Rows(0)
            fSubcontractorDef.ShowDialog(Me)
            fSubcontractorDef.Dispose()

            If gReturnKeyValue = "" Then Exit Sub

            SubcontractorNo = gReturnKeyValue

            '重新取出資料
            Call funLoadSubcontractor()

            If GetIssueState() = Issue.Unfrozen Then
                ugrRow = FindRecordPosition(iugSubcontractor, "SubcontractorNo", SubcontractorNo)
                If Not ugrRow Is Nothing Then
                    Me.iugSubcontractor.iMESUltraGrid.ActiveRow = ugrRow
                    Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected = True
                End If
            End If

        End If
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click



        '1.先檢查是否為單筆,是:將其Selecte
        If Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing Then Exit Sub
        If iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow Then Exit Sub
        Cursor.Current = Cursors.WaitCursor
        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected Then
            Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected = True
        End If

        '2.Multi
        If Me.iugSubcontractor.iMESUltraGrid.Selected.Rows.Count > 0 Then
            If Me.iugSubcontractor.iMESUltraGrid.Selected.Rows.Item(0).IsGroupByRow Then
                Exit Sub 'Selected.Rows,不會包含GroupRow & 一般的Row在一起,故若是GroupRow不做任何處理
            End If
            If iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-100001", "[%ARE YOU SURE TO DELETE ALL SELECTED RECORDS%]"), MsgBoxStyle.OkCancel + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2, Me.Text) = MsgBoxResult.Cancel Then
                Exit Sub
            End If

            '共用資料
            Dim XmlDoc As New XmlDocument
            Dim blnReLoad As Boolean = False
            Dim intIssueState As Integer

            strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
            For i = 0 To Me.iugSubcontractor.iMESUltraGrid.Selected.Rows.Count - 1
                intIssueState = Me.iugSubcontractor.iMESUltraGrid.Selected.Rows(i).Cells("IssueState").Value
                If intIssueState = 0 Or intIssueState = -1 Or intIssueState = 2 Then '狀態為Unforzen或Unused時直接刪除

                    strParameter = CombineXMLParameter("SubcontractorNo", "SubcontractorNo", "String", CInput(Me.iugSubcontractor.iMESUltraGrid.Selected.Rows(i).Cells("SubcontractorNo").Value.ToString), "")
                    strParameter = strParameter & CombineXMLParameter("issuestate", "IssueState", "String", CInput(intIssueState), "")
                    strParameter = strParameter & CombineXMLParameter("datastamp", "DataStamp", "Integer", iugSubcontractor.iMESUltraGrid.Selected.Rows(i).Cells("DataStamp").Value, "")
                    InXml = CombineXMLRequest(strIdentity, strParameter)
                    Try
                        ' 2016 YF, OutXml = wsENT.DelSubcontractor(InXml)
                        'OutXml = InvokeSrv("wsENT.DelSubcontractor", InXml)
                        OutXml = InvokeSrv("SXS.wsENT.DelSubcontractor", InXml)

                        XmlDoc.LoadXml(OutXml)
                        If ChkExecutionSuccess(XmlDoc) Then
                            If Not blnReLoad Then blnReLoad = True
                        Else
                            '找出Exception訊並顯示出來
                            ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                            Exit For
                        End If
                    Catch ex As Exception
                        'MsgBox("Unexpected Error. Delete failed," & e1.Message, MsgBoxStyle.Exclamation)
                        ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
                        Exit For
                    End Try
                Else
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200021", "[%NOT ALLOWED TO delete%]"), MsgBoxStyle.Exclamation, Me.Text)
                End If
            Next

            XmlDoc = Nothing

            If blnReLoad Then

                Call funLoadSubcontractor()

                Call funShowActiveDetail()

            End If

        End If

        Cursor.Current = Cursors.Default

    End Sub

    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click



        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing Then
            'IsGroupByRow不做任何處理
            If iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow Then
                Exit Sub
            End If
            Dim Rows As DataRow()

            '找出DataSet中在目前游標列的資料列(DataRow)
            Rows = dsENT.Tables(tblENTSubcontractor).Select("SubcontractorNo = '" _
                & Replace(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString, "'", "''") & "'")

            Dim fSubcontractorDef As New frmTestData21681Def
            fSubcontractorDef.DefMode = 2
            fSubcontractorDef.EditDataRow = Rows(0)
            fSubcontractorDef.ShowDialog(Me)

            If gReturnKeyValue = "" Then Exit Sub

            SubcontractorNo = gReturnKeyValue

            '重新取出資料
            Call funLoadSubcontractor()

            If GetIssueState() = Issue.Unfrozen Then
                ugrRow = FindRecordPosition(iugSubcontractor, "SubcontractorNo", SubcontractorNo)
                If Not ugrRow Is Nothing Then
                    Me.iugSubcontractor.iMESUltraGrid.ActiveRow = ugrRow
                    Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected = True
                End If
            End If

        End If
    End Sub

    Private Sub btnApprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApprove.Click



        '1.先檢查是否為單筆,是:將其Selecte
        If Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing Then Exit Sub
        If iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow Then Exit Sub
        Cursor.Current = Cursors.WaitCursor
        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected Then
            Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Selected = True
        End If

        '2.Multi
        If Me.iugSubcontractor.iMESUltraGrid.Selected.Rows.Count > 0 Then
            If Me.iugSubcontractor.iMESUltraGrid.Selected.Rows.Item(0).IsGroupByRow Then
                Exit Sub 'Selected.Rows,不會包含GroupRow & 一般的Row在一起,故若是GroupRow不做任何處理
            End If
            If iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-100002", "[%ARE YOU SURE TO APPROVE ALL SELECTED RECORDS%]"), MsgBoxStyle.OkCancel + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2, Me.Text) = MsgBoxResult.Cancel Then
                Exit Sub
            End If

            '共用資料
            Dim XmlDoc As New XmlDocument
            Dim blnReLoad As Boolean = False
            Dim intIssueState As Integer

            strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
            For i = 0 To Me.iugSubcontractor.iMESUltraGrid.Selected.Rows.Count - 1
                intIssueState = Me.iugSubcontractor.iMESUltraGrid.Selected.Rows(i).Cells("IssueState").Value
                If intIssueState = 0 Then
                    strParameter = CombineXMLParameter("SubcontractorNo", "SubcontractorNo", "String", CInput(Me.iugSubcontractor.iMESUltraGrid.Selected.Rows(i).Cells("SubcontractorNo").Value.ToString), "")
                    strParameter += CombineXMLParameter("issuestate", "IssueState", "String", intIssueState, "")
                    strParameter += CombineXMLParameter("creator", "Creator", "String", gUserNo, "")
                    strParameter = strParameter & CombineXMLParameter("datastamp", "DataStamp", "Integer", iugSubcontractor.iMESUltraGrid.Selected.Rows(i).Cells("DataStamp").Value, "")
                    InXml = CombineXMLRequest(strIdentity, strParameter)
                    Try
                        ' 2016 YF, OutXml = wsENT.ApproveSubcontractor(InXml)
                        'OutXml = InvokeSrv("wsENT.ApproveSubcontractor", InXml)
                        OutXml = InvokeSrv("SXS.wsENT.ApproveSubcontractor", InXml)

                        XmlDoc.LoadXml(OutXml)
                        If ChkExecutionSuccess(XmlDoc) Then
                            If Not blnReLoad Then blnReLoad = True
                        Else
                            '找出Exception訊並顯示出來
                            ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                            Exit For
                        End If
                    Catch ex As Exception
                        'MsgBox("Unexpected Error. Approve failed," & e1.Message, MsgBoxStyle.Exclamation)
                        ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
                        Exit For
                    End Try
                Else
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200021", "[%NOT ALLOW TO APPROVE%]"), MsgBoxStyle.Exclamation, Me.Text)
                End If
            Next

            XmlDoc = Nothing

            If blnReLoad Then

                Call funLoadSubcontractor()

                Call funShowActiveDetail()

            End If

        End If

        Cursor.Current = Cursors.Default

    End Sub

    Private Sub btnDAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDAdd.Click

        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing Then

            'Dim Rows As DataRow()
            Dim fSubcontractorContDef As New frmTestData21681ContDef

            fSubcontractorContDef.DefMode = 0
            fSubcontractorContDef.SubcontractorNo = Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString
            fSubcontractorContDef.ShowDialog(Me)

            If gReturnKeyValue = "" Then Exit Sub

            ContactorName = gReturnKeyValue

            '重新取出資料
            Call funLoadSubcontractorCont(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString)

            ugrRow = FindRecordPosition(iugDetail, "ContactorName", ContactorName)
            If Not ugrRow Is Nothing Then
                Me.iugDetail.iMESUltraGrid.ActiveRow = ugrRow
                Me.iugDetail.iMESUltraGrid.ActiveRow.Selected = True
            End If

        End If
    End Sub

    Private Sub btnDEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDEdit.Click

        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing And Not Me.iugDetail.iMESUltraGrid.ActiveRow Is Nothing Then
            If iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow OrElse iugDetail.iMESUltraGrid.ActiveRow.IsGroupByRow Then Exit Sub
            Dim Rows As DataRow()

            '找出DataSet中在目前游標列的資料列(DataRow)
            Rows = dsENT.Tables(tblENTSubcontractorCont).Select("SubcontractorNo = '" _
                & Replace(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString, "'", "''") & "'" _
                & " And ContactorName = '" & Replace(Me.iugDetail.iMESUltraGrid.ActiveRow.Cells("ContactorName").Value.ToString, "'", "''") & "'")

            Dim fSubcontractorContDef As New frmTestData21681ContDef
            fSubcontractorContDef.DefMode = 1
            fSubcontractorContDef.EditDataRow = Rows(0)
            fSubcontractorContDef.SubcontractorNo = Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString
            fSubcontractorContDef.ShowDialog(Me)

            If gReturnKeyValue = "" Then Exit Sub

            ContactorName = gReturnKeyValue

            '重新取出資料
            Call funLoadSubcontractorCont(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString)

            ugrRow = FindRecordPosition(iugDetail, "ContactorName", ContactorName)
            If Not ugrRow Is Nothing Then
                Me.iugDetail.iMESUltraGrid.ActiveRow = ugrRow
                Me.iugDetail.iMESUltraGrid.ActiveRow.Selected = True
            End If
        Else

            Exit Sub
        End If

    End Sub

    Private Sub btnDDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDDel.Click


        '1.先檢查是否為單筆,是:將其Selecte
        If Me.iugDetail.iMESUltraGrid.ActiveRow Is Nothing Then Exit Sub
        If iugDetail.iMESUltraGrid.ActiveRow.IsGroupByRow Then Exit Sub

        Cursor.Current = Cursors.WaitCursor

        If Not Me.iugDetail.iMESUltraGrid.ActiveRow.Selected Then
            Me.iugDetail.iMESUltraGrid.ActiveRow.Selected = True
        End If

        '2.Multi
        If Me.iugDetail.iMESUltraGrid.Selected.Rows.Count > 0 Then
            If Me.iugDetail.iMESUltraGrid.Selected.Rows.Item(0).IsGroupByRow Then
                Exit Sub 'Selected.Rows,不會包含GroupRow & 一般的Row在一起,故若是GroupRow不做任何處理
            End If
            If iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-100001", "[%ARE YOU SURE TO DELETE ALL SELECTED RECORDS%]"), MsgBoxStyle.OkCancel + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2, Me.Text) = MsgBoxResult.Cancel Then
                Exit Sub
            End If

            '共用資料
            Dim XmlDoc As New XmlDocument
            Dim blnReLoad As Boolean = False
            Dim intIssueState As Integer

            strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
            For i = 0 To Me.iugDetail.iMESUltraGrid.Selected.Rows.Count - 1
                strParameter = CombineXMLParameter("SubcontractorNo", "SubcontractorNo", "String", CInput(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString), "")
                strParameter = strParameter & CombineXMLParameter("ContactorName", "ContactorName", "String", CInput(Me.iugDetail.iMESUltraGrid.Selected.Rows(i).Cells("ContactorName").Value.ToString), "")
                InXml = CombineXMLRequest(strIdentity, strParameter)
                Try
                    ' 2016 YF, OutXml = wsENT.DelSubcontractorCont(InXml)
                    'OutXml = InvokeSrv("wsENT.DelSubcontractorCont", InXml)
                    OutXml = InvokeSrv("SXS.wsENT.DelSubcontractorCont", InXml)

                    XmlDoc.LoadXml(OutXml)
                    If ChkExecutionSuccess(XmlDoc) Then
                        If Not blnReLoad Then blnReLoad = True
                    Else
                        '找出Exception訊並顯示出來
                        ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                        Exit For
                    End If
                Catch ex As Exception
                    'MsgBox("Unexpected Error. Delete failed," & e1.Message, MsgBoxStyle.Exclamation)
                    ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
                    Exit For
                End Try

            Next

            XmlDoc = Nothing

            If blnReLoad Then Call funLoadSubcontractorCont(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString)

        End If

        Cursor.Current = Cursors.Default

    End Sub

    Private Sub btnDCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDCopy.Click

        If Not Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing And Not Me.iugDetail.iMESUltraGrid.ActiveRow Is Nothing Then
            If iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow OrElse iugDetail.iMESUltraGrid.ActiveRow.IsGroupByRow Then Exit Sub
            Dim Rows As DataRow()

            '找出DataSet中在目前游標列的資料列(DataRow)
            Rows = dsENT.Tables(tblENTSubcontractorCont).Select("SubcontractorNo = '" _
                & Replace(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString, "'", "''") & "'" _
                & " And ContactorName = '" & Replace(Me.iugDetail.iMESUltraGrid.ActiveRow.Cells("ContactorName").Value.ToString, "'", "''") & "'")

            Dim fSubcontractorContDef As New frmTestData21681ContDef
            fSubcontractorContDef.DefMode = 2
            fSubcontractorContDef.EditDataRow = Rows(0)
            fSubcontractorContDef.SubcontractorNo = Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString
            fSubcontractorContDef.ShowDialog(Me)

            If gReturnKeyValue = "" Then Exit Sub

            ContactorName = gReturnKeyValue

            '重新取出資料
            Call funLoadSubcontractorCont(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString)

            ugrRow = FindRecordPosition(iugDetail, "ContactorName", ContactorName)
            If Not ugrRow Is Nothing Then
                Me.iugDetail.iMESUltraGrid.ActiveRow = ugrRow
                Me.iugDetail.iMESUltraGrid.ActiveRow.Selected = True
            End If
        Else

            Exit Sub
        End If

    End Sub

    Private Sub btnEMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEMail.Click

        If Not Me.iugDetail.iMESUltraGrid.ActiveRow Is Nothing Then
            If iugDetail.iMESUltraGrid.ActiveRow.IsGroupByRow Then Exit Sub
            Dim Rows As DataRow()
            Dim proMail As New System.Diagnostics.Process
            Dim strAccount As String

            Rows = dsENT.Tables(tblENTSubcontractorCont).Select("SubcontractorNo = '" _
                & Replace(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString, "'", "''") & "'" _
                & " And ContactorName = '" & Replace(Me.iugDetail.iMESUltraGrid.ActiveRow.Cells("ContactorName").Value.ToString, "'", "''") & "'")

            strAccount = "mailto:" & Rows(0).Item("EMail").ToString
            proMail.Start(strAccount)

        End If

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Protected Overrides Sub btnQuery_Click(sender As Object, e As EventArgs)
        Cursor.Current = Cursors.WaitCursor

        funLoadSubcontractor()

        Cursor.Current = Cursors.Default
    End Sub

#Region "Ultra Grid"

    Private Sub iugSubcontractor_iMESUltraGrid_InitializeLayOut(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles iugSubcontractor.iMESUltraGrid_InitializeLayOut

        With e.Layout
            With .Bands(0).Columns("SubcontractorNo")
                .Header.Caption = "SubcontractorNo"
                .Width = 110
                .Hidden = False
                .Header.VisiblePosition = 0
            End With
            With .Bands(0).Columns("SubcontractorName")
                .Header.Caption = "SubcontractorName"
                .Width = 110
                .Hidden = False
                .CellMultiLine = DefaultableBoolean.True
                .Header.VisiblePosition = 1
            End With
            With .Bands(0).Columns("Description")
                .Header.Caption = "Description"
                .Width = 110
                .Hidden = False
                .CellMultiLine = DefaultableBoolean.True
                .Header.VisiblePosition = 2
            End With
            With .Bands(0).Columns("Creator")
                .Header.Caption = "Creator"
                .Width = 80
                .Hidden = False
                .Header.VisiblePosition = 3
            End With
            With .Bands(0).Columns("CreateDate")
                .Header.Caption = "CreateDate"
                .Width = 150
                .Format = "yyyy/MM/dd HH:mm:ss"
                .Hidden = False
                .Header.VisiblePosition = 4
            End With
            With .Bands(0).Columns("IssueState")
                .Header.Caption = "IssueState"
                .Width = 114
                .Hidden = True
                .Header.VisiblePosition = 5
            End With
            With .Bands(0).Columns("Reviser")
                .Header.Caption = "Reviser"
                .Width = 80
                .Hidden = False
                .Header.VisiblePosition = 6
            End With
            With .Bands(0).Columns("ReviseDate")
                .Header.Caption = "ReviseDate"
                .Width = 150
                .Format = "yyyy/MM/dd HH:mm:ss"
                .Hidden = False
                .Header.VisiblePosition = 7
            End With
            With e.Layout.Bands(0).Columns("DataStamp")
                .Hidden = True
            End With
        End With

        '語系切換
        Call ExeChangeResource(Me, gLanguageMode)
    End Sub

    Private Sub iugSubcontractor_iMESUltraGrid_AfterRowActivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles iugSubcontractor.iMESUltraGrid_AfterRowActivate

        'IsGroupByRow不做任何處理
        If Not iugSubcontractor.iMESUltraGrid.ActiveRow.IsGroupByRow Then
            Call funLoadSubcontractorCont(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString)
        Else
            Exit Sub
        End If

    End Sub

    Private Sub iugDetail_iMESUltraGrid_InitializeLayOut(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles iugDetail.iMESUltraGrid_InitializeLayOut

        With e.Layout
            With .Bands(0).Columns("SubcontractorNo")
                .Header.Caption = "SubcontractorNo"
                .Width = 110
                .Hidden = False
                .Header.VisiblePosition = 0
            End With
            With .Bands(0).Columns("ContactorName")
                .Header.Caption = "ContactorName"
                .Width = 110
                .Hidden = False
                .Header.VisiblePosition = 1
            End With
            With .Bands(0).Columns("TelNo")
                .Header.Caption = "TelNo"
                .Width = 110
                .Hidden = False
                .Header.VisiblePosition = 2
            End With
            With .Bands(0).Columns("FaxNo")
                .Header.Caption = "FaxNo"
                .Width = 110
                .Hidden = False
                .Header.VisiblePosition = 3
            End With
            With .Bands(0).Columns("Title")
                .Header.Caption = "Title"
                .Width = 110
                .Hidden = False
                .Header.VisiblePosition = 4
            End With
            With .Bands(0).Columns("Address")
                .Header.Caption = "Address"
                .Width = 110
                .Hidden = False
                .CellMultiLine = DefaultableBoolean.True
                .Header.VisiblePosition = 5
            End With
            With .Bands(0).Columns("EMail")
                .Header.Caption = "EMail"
                .Width = 150
                .Hidden = False
                .CellAppearance.ForeColor = System.Drawing.Color.Blue
                .CellAppearance.FontData.Underline = DefaultableBoolean.True
                .Header.VisiblePosition = 6
            End With
            With .Bands(0).Columns("Description")
                .Header.Caption = "Description"
                .Width = 200
                .Hidden = False
                .CellMultiLine = DefaultableBoolean.True
                .Header.VisiblePosition = 7
            End With
            With .Bands(0).Columns("Creator")
                .Header.Caption = "Creator"
                .Width = 80
                .Hidden = False
                .Header.VisiblePosition = 8
            End With
            With .Bands(0).Columns("CreateDate")
                .Header.Caption = "CreateDate"
                .Width = 150
                .Format = "yyyy/MM/dd HH:mm:ss"
                .Hidden = False
                .Header.VisiblePosition = 9
            End With
            With .Bands(0).Columns("Reviser")
                .Header.Caption = "Reviser"
                .Width = 80
                .Hidden = False
                .Header.VisiblePosition = 10
            End With
            With .Bands(0).Columns("ReviseDate")
                .Header.Caption = "ReviseDate"
                .Width = 150
                .Format = "yyyy/MM/dd HH:mm:ss"
                .Hidden = False
                .Header.VisiblePosition = 11
            End With
            With e.Layout.Bands(0).Columns("DataStamp")
                .Hidden = True
            End With
        End With

        '語系切換
        Call ExeChangeResource(Me, gLanguageMode)
    End Sub

#End Region

#Region "Load Function"

    '//取出tblENTSubcontractor 外包商資料

    Private Sub funLoadSubcontractor()

        '先判斷是否dataset中已有ENTSubcontractor之datatable,若有,需先remove否則會有錯誤
        If Not IsNothing(dsENT.Tables(tblENTSubcontractor)) Then
            dsENT.Tables.Remove(tblENTSubcontractor)
        End If

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        '加上IssueState要求取出所有資料
        strParameter = CombineXMLParameter("issuestate", "IssueState", "Integer", defInteger, "")
        '加上查詢條件 cboSearchFieldName,txtSearchFieldValue
        strParameter += CombineXMLQueryCondition()
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            ' 2016 YF, OutXml = wsENT.LoadSubcontractor(InXml)
            'OutXml = InvokeSrv("wsENT.LoadSubcontractor", InXml)
            OutXml = InvokeSrv("SXS.wsTest21681.LoadTestDataBasis_21681", InXml)

            Dim XmlDoc As New XmlDocument   '處理Xml字串之物件?

            '利用XmlDoc物件處理ReturnValue 
            XmlDoc.LoadXml(OutXml)

            If ChkExecutionSuccess(XmlDoc) Then
                '讀取取出資料表之名稱

                tblENTSubcontractor = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("TestDataBasis").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題

                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadSubcontractor").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsENT.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If

                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadSubcontractor").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsENT.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                strFilter = ""
                Select Case GetIssueState()
                    Case Issue.Unfrozen
                        strFilter = FilterByInteger(strFilter, "IssueState", 0)
                    Case Issue.Pending
                        strFilter = FilterByInteger(strFilter, "IssueState", 1)
                    Case Issue.Active
                        strFilter = FilterByInteger(strFilter, "IssueState", 2)
                    Case Issue.Unused
                        strFilter = FilterByInteger(strFilter, "IssueState", -1)
                End Select

                dsENT.Tables(tblENTSubcontractor).DefaultView.RowFilter = strFilter
                dsENT.Tables(tblENTSubcontractor).DefaultView.Sort = "SubcontractorNo"

                Me.iugSubcontractor.iMESUltraGrid.DataSource = dsENT.Tables(tblENTSubcontractor).DefaultView

            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If

            XmlDoc = Nothing

        Catch ex As Exception
            'MsgBox("Unexpected Error. Load ENT Subcontractor Failed!!," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub

    '//取出tblENTSubcontractorCont聯絡人資料

    Private Sub funLoadSubcontractorCont(ByRef SubcontractorNo As String)

        If Not IsNothing(dsENT.Tables(tblENTSubcontractorCont)) Then
            dsENT.Tables.Remove(tblENTSubcontractorCont)
        End If

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("SubcontractorNo", "SubcontractorNo", "String", SubcontractorNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            ' 2016 YF, OutXml = wsENT.LoadSubcontractorCont(InXml)
            'OutXml = InvokeSrv("wsENT.LoadSubcontractorCont", InXml)
            OutXml = InvokeSrv("SXS.wsTest21681.LoadSubcontractorCont", InXml)

            Dim XmlDoc As New XmlDocument   '處理Xml字串之物件?

            '利用XmlDoc物件處理ReturnValue 
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '讀取取出資料表之名稱

                tblENTSubcontractorCont = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadSubcontractorcont").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadSubcontractorcont").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsENT.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If

                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadSubcontractorcont").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsENT.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                Me.iugDetail.iMESUltraGrid.DataSource = dsENT.Tables(tblENTSubcontractorCont).DefaultView

            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
            End If

            XmlDoc = Nothing

        Catch ex As Exception
            'MsgBox("Unexpected Error. Load ENT Subcontractor Cont Failed!!," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub

    Private Sub funShowActiveDetail()

        If Me.iugSubcontractor.iMESUltraGrid.ActiveRow Is Nothing Then
            Me.iugDetail.iMESUltraGrid.DataSource = Nothing
        Else
            Call funLoadSubcontractorCont(Me.iugSubcontractor.iMESUltraGrid.ActiveRow.Cells("SubcontractorNo").Value.ToString)
        End If

    End Sub

    Private Sub funiMESUltraGridIni()

        'iugSubcontractor 初始設定
        With Me.iugSubcontractor.iMESUltraGrid
            .Text = ""
            .DisplayLayout.GroupByBox.Hidden = True
            .DisplayLayout.UseFixedHeaders = False
        End With

        '系統會以UserNo做為Layout的檔名

        iugSubcontractor.UserNo = gUserNo

        'iugDetail 初始設定
        With Me.iugDetail.iMESUltraGrid.DisplayLayout
            .GroupByBox.Hidden = True
            .Override.ExpansionIndicator = ShowExpansionIndicator.Default
            .ViewStyle = ViewStyle.SingleBand
            .RowConnectorStyle = RowConnectorStyle.Default

        End With

        '系統會以UserNo做為Layout的檔名

        iugDetail.UserNo = gUserNo

    End Sub


#End Region

End Class

