Imports iMESExceptionManager

Imports Infragistics.Win.UltraWinGrid
Imports COM_ERP.clsTipTop
Imports COM_ERP.clsTipTop_ICD
Imports COM_ERP.clsCommon
Imports Infragistics.Win

''' <summary>
''' 2016/12/26 YF, 增加新制多人加工(btnOperator), 先將舊有的多人加工隱藏(btnMultiUser)
''' </summary>
Public Class frmBR_L_CO_GEN
    Inherits System.Windows.Forms.Form

    '//Public Variables
    Public LotNo As String = defString
    Public UserId As String = defString
    Public PrivFunNo As String = defString

    '//Web Service相關變數
    Dim tmpStringReader As System.IO.StringReader
    Dim InXml, OutXml, strIdentity, strParameter, XmlData, XmlSchema As String

    '//資料表相關變數
    Dim dsWIP, dsTemp, dsDefine As New DataSet
    Dim dtKeyIn, dtMLot As DataTable
    Dim drAdd As DataRow
    Dim tbllotbasis, tblLotState, tblTAttrib, tblStuInfo, tblTMaterial, tblTEquipment, tblOPError, tblSYSParameter, tblProductBasis, tblOEMOBasis, tblParameter, tblSWRJoinLog, strBinState, strSysBin As String
    Dim tblSubstituteMaterial, tblOPBasis As String

    '//其他共用變數
    Dim PhaseNo As Integer
    Dim ugrRow As Infragistics.Win.UltraWinGrid.UltraGridRow
    Dim calCustomer As New clsCalculator
    Dim dvSysBin As DataView
    Dim dtBinNew As DataTable
    Dim iGoodBinStateQty As Integer = 0
    'Reverse
    Dim RevLotSerial As String = defString
    Dim RevLotStamp As Long = defInteger
    Dim strDefaultValue As String
    Dim editor As Infragistics.Win.DateTimeEditor

    ' 2016/08/30 YF, ObjectFile物件
    Dim ObjectFileHandler As COM_Utility.ObjectFileHandler
    '2019/01/19 Eric 系統參數EnableSWR_CICO
    Dim strEnableSWR_CICO As String = defString
    '2019/02/12 Eric 特殊生產需求是否有資料
    Dim blnShowSWR As Boolean = False

    '2019/9/5, ning, 料批先進先出與回溫卡控
    Dim dtAllMTLLot As DataTable            '所有可用料批資料
    Dim tblTMaterialLot, tblMTLProperty As String

    Dim blnByEQP As Boolean = False
    Dim HaveComponent, HaveLevel As Boolean

    Dim strTableName As String
    Dim vlMaterialLevel As New ValueList
    Dim vlStuInfoIsSelected As New ValueList
    Dim dsINV As New DataSet
    Dim strRaw As String
    '2021/06/10 子設備
    Dim strPara As String
    Dim blnChamber As Boolean
    '新设备上料14278
    Dim dsOE As New DataSet   '資料集：儲存取回之資料?
    Dim strMOList As String '儲存取回資料表的名稱?

    Friend WithEvents chkUpdCheckOutTime As CheckBox
    Friend WithEvents txtUnionProductNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtUnionProductVersion As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents btnGetProduct As Infragistics.Win.Misc.UltraButton
    Friend WithEvents txtUnionProductUnit As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents btnSWR As Infragistics.Win.Misc.UltraButton
    Friend WithEvents chkUnionProductNo As CheckBox
    Friend WithEvents btnBinStateAdjust As Infragistics.Win.Misc.UltraButton
    Friend WithEvents uplAll As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uegMaterial_KeyIn2 As Infragistics.Win.Misc.UltraExpandableGroupBox
    Friend WithEvents UltraExpandableGroupBoxPanel4 As Infragistics.Win.Misc.UltraExpandableGroupBoxPanel
    Friend WithEvents UltraPanel4 As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uplMaterial_KeyIn As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uplKeyIn As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents UltraSplitter2 As Infragistics.Win.Misc.UltraSplitter
    Friend WithEvents uplMaterial As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uegAttrib_Equipment As Infragistics.Win.Misc.UltraExpandableGroupBox
    Friend WithEvents UltraExpandableGroupBoxPanel2 As Infragistics.Win.Misc.UltraExpandableGroupBoxPanel
    Friend WithEvents UltraPanel2 As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uplAttrib_Equipment As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uplEquipment As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents UltraSplitter1 As Infragistics.Win.Misc.UltraSplitter
    Friend WithEvents uplAttrib As Infragistics.Win.Misc.UltraPanel
    Friend WithEvents uegLotInfo As Infragistics.Win.Misc.UltraExpandableGroupBox
    Friend WithEvents UltraExpandableGroupBoxPanel1 As Infragistics.Win.Misc.UltraExpandableGroupBoxPanel
    Friend WithEvents iugStuInfo As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents UltraPanel1 As Infragistics.Win.Misc.UltraPanel

#Region " Windows Form 設計工具產生的程式碼 "

    Public Sub New()
        MyBase.New()

        '此呼叫為 Windows Form 設計工具的必要項。

        InitializeComponent()

        '在 InitializeComponent() 呼叫之後加入所有的初始設定
        ' 2016/08/30 YF, 開另一條執行緒建立會使用到的物件
        Threading.ThreadPool.QueueUserWorkItem(New Threading.WaitCallback(
                Sub(pState As Object)
                    ' 呼叫COM_Utility.ObjectFileHandler建構子, 傳入要載入的ObjectID
                    Me.ObjectFileHandler = New COM_Utility.ObjectFileHandler("WP_OperatorLogIn_Lot", "WP_MaterialQtyInput_Main", "WP_SWRBasisRead")
                End Sub))

    End Sub

    'Form 覆寫 Dispose 以清除元件清單。

    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

    '為 Windows Form 設計工具的必要項
    Private components As System.ComponentModel.IContainer

    '注意: 以下為 Windows Form 設計工具所需的程序

    '您可以使用 Windows Form 設計工具進行修改。

    '請勿使用程式碼編輯器來修改這些程序。

    Friend WithEvents txtMaterialLotNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblMaterialLotNo As System.Windows.Forms.Label
    Friend WithEvents btnOperator As Infragistics.Win.Misc.UltraButton
    Friend WithEvents SBar1 As System.Windows.Forms.StatusBar
    Friend WithEvents SBarPanel1 As System.Windows.Forms.StatusBarPanel
    Friend WithEvents SBarPanel4 As System.Windows.Forms.StatusBarPanel
    Friend WithEvents SBarPanel2 As System.Windows.Forms.StatusBarPanel
    Friend WithEvents SBarPanel3 As System.Windows.Forms.StatusBarPanel
    Friend WithEvents txtOPNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblOPDescription As System.Windows.Forms.Label
    Friend WithEvents txtProductNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblProductNo As System.Windows.Forms.Label
    Friend WithEvents txtCustomerLotNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtMONo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtShiftNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtEmployeeNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtAreaNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtPriority As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtSysUnitNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtSysQty As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtCurUnitNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtCurQty As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtOPDescription As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents txtLotNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblPriority As System.Windows.Forms.Label
    Friend WithEvents lblMONo As System.Windows.Forms.Label
    Friend WithEvents lblCustomerLotNo As System.Windows.Forms.Label
    Friend WithEvents lblShiftNo As System.Windows.Forms.Label
    Friend WithEvents lblOPNo As System.Windows.Forms.Label
    Friend WithEvents lblEmployeeNo As System.Windows.Forms.Label
    Friend WithEvents lblAreaNo As System.Windows.Forms.Label
    Friend WithEvents lblSysQty As System.Windows.Forms.Label
    Friend WithEvents lblCurQty As System.Windows.Forms.Label
    Friend WithEvents lblLotNo As System.Windows.Forms.Label
    Friend WithEvents txtLotRecord As System.Windows.Forms.RichTextBox
    Friend WithEvents iugKeyIn As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents lblLotRecord As System.Windows.Forms.Label
    Friend WithEvents btnClose As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnConfirm As Infragistics.Win.Misc.UltraButton
    Friend WithEvents iugMaterial As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents iugEquipment As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents iugAttrib As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents gbxLotInfo As System.Windows.Forms.GroupBox
    Friend WithEvents txtMaterialNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblMaterialNo As System.Windows.Forms.Label
    Friend WithEvents gbxMaterial As System.Windows.Forms.GroupBox
    Friend WithEvents btnKeyIn As Infragistics.Win.Misc.UltraButton
    Friend WithEvents btnDel As Infragistics.Win.Misc.UltraButton
    Friend WithEvents iugError As iMESUltraGrid.iMESUltraGridControl
    Friend WithEvents gbxError As System.Windows.Forms.GroupBox
    Friend WithEvents txtErrorNo As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblErrorNo As System.Windows.Forms.Label
    Friend WithEvents txtErrorQty As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents lblErrorQty As System.Windows.Forms.Label
    Friend WithEvents lblupdcheckouttime As System.Windows.Forms.Label
    Friend WithEvents dtpcheckouttime As System.Windows.Forms.DateTimePicker
    Friend WithEvents txtOPName As Infragistics.Win.UltraWinEditors.UltraTextEditor
    Friend WithEvents btnMultiUser As Infragistics.Win.Misc.UltraButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SBar1 = New System.Windows.Forms.StatusBar()
        Me.SBarPanel1 = New System.Windows.Forms.StatusBarPanel()
        Me.SBarPanel2 = New System.Windows.Forms.StatusBarPanel()
        Me.SBarPanel3 = New System.Windows.Forms.StatusBarPanel()
        Me.SBarPanel4 = New System.Windows.Forms.StatusBarPanel()
        Me.gbxLotInfo = New System.Windows.Forms.GroupBox()
        Me.txtOPName = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtOPNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.lblOPDescription = New System.Windows.Forms.Label()
        Me.txtProductNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtCustomerLotNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtMONo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtShiftNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtEmployeeNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtAreaNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtPriority = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtSysUnitNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtSysQty = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtCurUnitNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtCurQty = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtOPDescription = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtLotNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.lblPriority = New System.Windows.Forms.Label()
        Me.lblMONo = New System.Windows.Forms.Label()
        Me.lblCustomerLotNo = New System.Windows.Forms.Label()
        Me.lblShiftNo = New System.Windows.Forms.Label()
        Me.lblOPNo = New System.Windows.Forms.Label()
        Me.lblEmployeeNo = New System.Windows.Forms.Label()
        Me.lblAreaNo = New System.Windows.Forms.Label()
        Me.lblSysQty = New System.Windows.Forms.Label()
        Me.lblCurQty = New System.Windows.Forms.Label()
        Me.lblLotNo = New System.Windows.Forms.Label()
        Me.lblProductNo = New System.Windows.Forms.Label()
        Me.txtLotRecord = New System.Windows.Forms.RichTextBox()
        Me.iugKeyIn = New iMESUltraGrid.iMESUltraGridControl()
        Me.lblLotRecord = New System.Windows.Forms.Label()
        Me.btnClose = New Infragistics.Win.Misc.UltraButton()
        Me.btnConfirm = New Infragistics.Win.Misc.UltraButton()
        Me.iugMaterial = New iMESUltraGrid.iMESUltraGridControl()
        Me.iugEquipment = New iMESUltraGrid.iMESUltraGridControl()
        Me.iugAttrib = New iMESUltraGrid.iMESUltraGridControl()
        Me.txtMaterialNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.lblMaterialNo = New System.Windows.Forms.Label()
        Me.gbxMaterial = New System.Windows.Forms.GroupBox()
        Me.btnKeyIn = New Infragistics.Win.Misc.UltraButton()
        Me.txtMaterialLotNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.lblMaterialLotNo = New System.Windows.Forms.Label()
        Me.btnDel = New Infragistics.Win.Misc.UltraButton()
        Me.iugError = New iMESUltraGrid.iMESUltraGridControl()
        Me.gbxError = New System.Windows.Forms.GroupBox()
        Me.txtErrorQty = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.lblErrorQty = New System.Windows.Forms.Label()
        Me.txtErrorNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.lblErrorNo = New System.Windows.Forms.Label()
        Me.dtpcheckouttime = New System.Windows.Forms.DateTimePicker()
        Me.lblupdcheckouttime = New System.Windows.Forms.Label()
        Me.btnMultiUser = New Infragistics.Win.Misc.UltraButton()
        Me.btnOperator = New Infragistics.Win.Misc.UltraButton()
        Me.chkUpdCheckOutTime = New System.Windows.Forms.CheckBox()
        Me.txtUnionProductNo = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.txtUnionProductVersion = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.btnGetProduct = New Infragistics.Win.Misc.UltraButton()
        Me.txtUnionProductUnit = New Infragistics.Win.UltraWinEditors.UltraTextEditor()
        Me.btnSWR = New Infragistics.Win.Misc.UltraButton()
        Me.chkUnionProductNo = New System.Windows.Forms.CheckBox()
        Me.btnBinStateAdjust = New Infragistics.Win.Misc.UltraButton()
        Me.uplAll = New Infragistics.Win.Misc.UltraPanel()
        Me.uegMaterial_KeyIn2 = New Infragistics.Win.Misc.UltraExpandableGroupBox()
        Me.UltraExpandableGroupBoxPanel4 = New Infragistics.Win.Misc.UltraExpandableGroupBoxPanel()
        Me.UltraPanel4 = New Infragistics.Win.Misc.UltraPanel()
        Me.uplMaterial_KeyIn = New Infragistics.Win.Misc.UltraPanel()
        Me.uplKeyIn = New Infragistics.Win.Misc.UltraPanel()
        Me.UltraSplitter2 = New Infragistics.Win.Misc.UltraSplitter()
        Me.uplMaterial = New Infragistics.Win.Misc.UltraPanel()
        Me.uegAttrib_Equipment = New Infragistics.Win.Misc.UltraExpandableGroupBox()
        Me.UltraExpandableGroupBoxPanel2 = New Infragistics.Win.Misc.UltraExpandableGroupBoxPanel()
        Me.UltraPanel2 = New Infragistics.Win.Misc.UltraPanel()
        Me.uplAttrib_Equipment = New Infragistics.Win.Misc.UltraPanel()
        Me.uplEquipment = New Infragistics.Win.Misc.UltraPanel()
        Me.iugStuInfo = New iMESUltraGrid.iMESUltraGridControl()
        Me.UltraSplitter1 = New Infragistics.Win.Misc.UltraSplitter()
        Me.uplAttrib = New Infragistics.Win.Misc.UltraPanel()
        Me.uegLotInfo = New Infragistics.Win.Misc.UltraExpandableGroupBox()
        Me.UltraExpandableGroupBoxPanel1 = New Infragistics.Win.Misc.UltraExpandableGroupBoxPanel()
        Me.UltraPanel1 = New Infragistics.Win.Misc.UltraPanel()
        CType(Me.SBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.SBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.SBarPanel3, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.SBarPanel4, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.gbxLotInfo.SuspendLayout()
        CType(Me.txtOPName, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtOPNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtProductNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtCustomerLotNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtMONo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtShiftNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtEmployeeNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtAreaNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtPriority, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtSysUnitNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtSysQty, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtCurUnitNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtCurQty, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtOPDescription, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtLotNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtMaterialNo, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.gbxMaterial.SuspendLayout()
        CType(Me.txtMaterialLotNo, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.gbxError.SuspendLayout()
        CType(Me.txtErrorQty, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtErrorNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtUnionProductNo, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtUnionProductVersion, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.txtUnionProductUnit, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.uplAll.ClientArea.SuspendLayout()
        Me.uplAll.SuspendLayout()
        CType(Me.uegMaterial_KeyIn2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.uegMaterial_KeyIn2.SuspendLayout()
        Me.UltraExpandableGroupBoxPanel4.SuspendLayout()
        Me.UltraPanel4.ClientArea.SuspendLayout()
        Me.UltraPanel4.SuspendLayout()
        Me.uplMaterial_KeyIn.ClientArea.SuspendLayout()
        Me.uplMaterial_KeyIn.SuspendLayout()
        Me.uplKeyIn.ClientArea.SuspendLayout()
        Me.uplKeyIn.SuspendLayout()
        Me.uplMaterial.ClientArea.SuspendLayout()
        Me.uplMaterial.SuspendLayout()
        CType(Me.uegAttrib_Equipment, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.uegAttrib_Equipment.SuspendLayout()
        Me.UltraExpandableGroupBoxPanel2.SuspendLayout()
        Me.UltraPanel2.ClientArea.SuspendLayout()
        Me.UltraPanel2.SuspendLayout()
        Me.uplAttrib_Equipment.ClientArea.SuspendLayout()
        Me.uplAttrib_Equipment.SuspendLayout()
        Me.uplEquipment.ClientArea.SuspendLayout()
        Me.uplEquipment.SuspendLayout()
        Me.uplAttrib.ClientArea.SuspendLayout()
        Me.uplAttrib.SuspendLayout()
        CType(Me.uegLotInfo, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.uegLotInfo.SuspendLayout()
        Me.UltraExpandableGroupBoxPanel1.SuspendLayout()
        Me.UltraPanel1.ClientArea.SuspendLayout()
        Me.UltraPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'SBar1
        '
        Me.SBar1.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.SBar1.Location = New System.Drawing.Point(0, 710)
        Me.SBar1.Name = "SBar1"
        Me.SBar1.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.SBarPanel1, Me.SBarPanel2, Me.SBarPanel3, Me.SBarPanel4})
        Me.SBar1.ShowPanels = True
        Me.SBar1.Size = New System.Drawing.Size(1008, 22)
        Me.SBar1.TabIndex = 13
        '
        'SBarPanel1
        '
        Me.SBarPanel1.Name = "SBarPanel1"
        '
        'SBarPanel2
        '
        Me.SBarPanel2.Name = "SBarPanel2"
        '
        'SBarPanel3
        '
        Me.SBarPanel3.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
        Me.SBarPanel3.Name = "SBarPanel3"
        Me.SBarPanel3.Width = 641
        '
        'SBarPanel4
        '
        Me.SBarPanel4.Alignment = System.Windows.Forms.HorizontalAlignment.Right
        Me.SBarPanel4.Name = "SBarPanel4"
        Me.SBarPanel4.Width = 150
        '
        'gbxLotInfo
        '
        Me.gbxLotInfo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.gbxLotInfo.Controls.Add(Me.txtOPName)
        Me.gbxLotInfo.Controls.Add(Me.txtOPNo)
        Me.gbxLotInfo.Controls.Add(Me.lblOPDescription)
        Me.gbxLotInfo.Controls.Add(Me.txtProductNo)
        Me.gbxLotInfo.Controls.Add(Me.txtCustomerLotNo)
        Me.gbxLotInfo.Controls.Add(Me.txtMONo)
        Me.gbxLotInfo.Controls.Add(Me.txtShiftNo)
        Me.gbxLotInfo.Controls.Add(Me.txtEmployeeNo)
        Me.gbxLotInfo.Controls.Add(Me.txtAreaNo)
        Me.gbxLotInfo.Controls.Add(Me.txtPriority)
        Me.gbxLotInfo.Controls.Add(Me.txtSysUnitNo)
        Me.gbxLotInfo.Controls.Add(Me.txtSysQty)
        Me.gbxLotInfo.Controls.Add(Me.txtCurUnitNo)
        Me.gbxLotInfo.Controls.Add(Me.txtCurQty)
        Me.gbxLotInfo.Controls.Add(Me.txtOPDescription)
        Me.gbxLotInfo.Controls.Add(Me.txtLotNo)
        Me.gbxLotInfo.Controls.Add(Me.lblPriority)
        Me.gbxLotInfo.Controls.Add(Me.lblMONo)
        Me.gbxLotInfo.Controls.Add(Me.lblCustomerLotNo)
        Me.gbxLotInfo.Controls.Add(Me.lblShiftNo)
        Me.gbxLotInfo.Controls.Add(Me.lblOPNo)
        Me.gbxLotInfo.Controls.Add(Me.lblEmployeeNo)
        Me.gbxLotInfo.Controls.Add(Me.lblAreaNo)
        Me.gbxLotInfo.Controls.Add(Me.lblSysQty)
        Me.gbxLotInfo.Controls.Add(Me.lblCurQty)
        Me.gbxLotInfo.Controls.Add(Me.lblLotNo)
        Me.gbxLotInfo.Controls.Add(Me.lblProductNo)
        Me.gbxLotInfo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.gbxLotInfo.Location = New System.Drawing.Point(0, 0)
        Me.gbxLotInfo.Name = "gbxLotInfo"
        Me.gbxLotInfo.Size = New System.Drawing.Size(1004, 126)
        Me.gbxLotInfo.TabIndex = 0
        Me.gbxLotInfo.TabStop = False
        Me.gbxLotInfo.Text = "Lot Information"
        '
        'txtOPName
        '
        Me.txtOPName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtOPName.Location = New System.Drawing.Point(742, 69)
        Me.txtOPName.Name = "txtOPName"
        Me.txtOPName.ReadOnly = True
        Me.txtOPName.Size = New System.Drawing.Size(258, 22)
        Me.txtOPName.TabIndex = 24
        '
        'txtOPNo
        '
        Me.txtOPNo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtOPNo.Location = New System.Drawing.Point(607, 69)
        Me.txtOPNo.Name = "txtOPNo"
        Me.txtOPNo.ReadOnly = True
        Me.txtOPNo.Size = New System.Drawing.Size(137, 22)
        Me.txtOPNo.TabIndex = 23
        '
        'lblOPDescription
        '
        Me.lblOPDescription.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblOPDescription.Location = New System.Drawing.Point(3, 97)
        Me.lblOPDescription.Name = "lblOPDescription"
        Me.lblOPDescription.Size = New System.Drawing.Size(80, 15)
        Me.lblOPDescription.TabIndex = 25
        Me.lblOPDescription.Text = "OP Description"
        Me.lblOPDescription.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtProductNo
        '
        Me.txtProductNo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtProductNo.Location = New System.Drawing.Point(607, 42)
        Me.txtProductNo.Name = "txtProductNo"
        Me.txtProductNo.ReadOnly = True
        Me.txtProductNo.Size = New System.Drawing.Size(188, 22)
        Me.txtProductNo.TabIndex = 14
        '
        'txtCustomerLotNo
        '
        Me.txtCustomerLotNo.Location = New System.Drawing.Point(87, 42)
        Me.txtCustomerLotNo.Name = "txtCustomerLotNo"
        Me.txtCustomerLotNo.ReadOnly = True
        Me.txtCustomerLotNo.Size = New System.Drawing.Size(179, 22)
        Me.txtCustomerLotNo.TabIndex = 10
        '
        'txtMONo
        '
        Me.txtMONo.Location = New System.Drawing.Point(341, 42)
        Me.txtMONo.Name = "txtMONo"
        Me.txtMONo.ReadOnly = True
        Me.txtMONo.Size = New System.Drawing.Size(179, 22)
        Me.txtMONo.TabIndex = 12
        '
        'txtShiftNo
        '
        Me.txtShiftNo.Location = New System.Drawing.Point(341, 69)
        Me.txtShiftNo.Name = "txtShiftNo"
        Me.txtShiftNo.ReadOnly = True
        Me.txtShiftNo.Size = New System.Drawing.Size(179, 22)
        Me.txtShiftNo.TabIndex = 21
        '
        'txtEmployeeNo
        '
        Me.txtEmployeeNo.Location = New System.Drawing.Point(87, 69)
        Me.txtEmployeeNo.Name = "txtEmployeeNo"
        Me.txtEmployeeNo.ReadOnly = True
        Me.txtEmployeeNo.Size = New System.Drawing.Size(179, 22)
        Me.txtEmployeeNo.TabIndex = 19
        '
        'txtAreaNo
        '
        Me.txtAreaNo.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtAreaNo.Location = New System.Drawing.Point(607, 15)
        Me.txtAreaNo.Name = "txtAreaNo"
        Me.txtAreaNo.ReadOnly = True
        Me.txtAreaNo.Size = New System.Drawing.Size(188, 22)
        Me.txtAreaNo.TabIndex = 5
        '
        'txtPriority
        '
        Me.txtPriority.Location = New System.Drawing.Point(341, 15)
        Me.txtPriority.Name = "txtPriority"
        Me.txtPriority.ReadOnly = True
        Me.txtPriority.Size = New System.Drawing.Size(179, 22)
        Me.txtPriority.TabIndex = 3
        '
        'txtSysUnitNo
        '
        Me.txtSysUnitNo.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtSysUnitNo.Location = New System.Drawing.Point(960, 42)
        Me.txtSysUnitNo.Name = "txtSysUnitNo"
        Me.txtSysUnitNo.ReadOnly = True
        Me.txtSysUnitNo.Size = New System.Drawing.Size(40, 22)
        Me.txtSysUnitNo.TabIndex = 17
        '
        'txtSysQty
        '
        Me.txtSysQty.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtSysQty.Location = New System.Drawing.Point(858, 42)
        Me.txtSysQty.Name = "txtSysQty"
        Me.txtSysQty.ReadOnly = True
        Me.txtSysQty.Size = New System.Drawing.Size(102, 22)
        Me.txtSysQty.TabIndex = 16
        '
        'txtCurUnitNo
        '
        Me.txtCurUnitNo.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtCurUnitNo.Location = New System.Drawing.Point(960, 15)
        Me.txtCurUnitNo.Name = "txtCurUnitNo"
        Me.txtCurUnitNo.ReadOnly = True
        Me.txtCurUnitNo.Size = New System.Drawing.Size(40, 22)
        Me.txtCurUnitNo.TabIndex = 8
        '
        'txtCurQty
        '
        Me.txtCurQty.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtCurQty.Location = New System.Drawing.Point(858, 15)
        Me.txtCurQty.Name = "txtCurQty"
        Me.txtCurQty.ReadOnly = True
        Me.txtCurQty.Size = New System.Drawing.Size(102, 22)
        Me.txtCurQty.TabIndex = 7
        '
        'txtOPDescription
        '
        Me.txtOPDescription.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtOPDescription.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtOPDescription.Location = New System.Drawing.Point(87, 96)
        Me.txtOPDescription.Name = "txtOPDescription"
        Me.txtOPDescription.ReadOnly = True
        Me.txtOPDescription.Size = New System.Drawing.Size(913, 22)
        Me.txtOPDescription.TabIndex = 26
        '
        'txtLotNo
        '
        Me.txtLotNo.Location = New System.Drawing.Point(87, 15)
        Me.txtLotNo.Name = "txtLotNo"
        Me.txtLotNo.ReadOnly = True
        Me.txtLotNo.Size = New System.Drawing.Size(179, 22)
        Me.txtLotNo.TabIndex = 1
        '
        'lblPriority
        '
        Me.lblPriority.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblPriority.Location = New System.Drawing.Point(271, 18)
        Me.lblPriority.Name = "lblPriority"
        Me.lblPriority.Size = New System.Drawing.Size(64, 15)
        Me.lblPriority.TabIndex = 2
        Me.lblPriority.Text = "Priority"
        Me.lblPriority.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblMONo
        '
        Me.lblMONo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMONo.Location = New System.Drawing.Point(271, 45)
        Me.lblMONo.Name = "lblMONo"
        Me.lblMONo.Size = New System.Drawing.Size(64, 15)
        Me.lblMONo.TabIndex = 11
        Me.lblMONo.Text = "MONo"
        Me.lblMONo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblCustomerLotNo
        '
        Me.lblCustomerLotNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCustomerLotNo.Location = New System.Drawing.Point(3, 45)
        Me.lblCustomerLotNo.Name = "lblCustomerLotNo"
        Me.lblCustomerLotNo.Size = New System.Drawing.Size(80, 15)
        Me.lblCustomerLotNo.TabIndex = 9
        Me.lblCustomerLotNo.Text = "Customer Lot No"
        Me.lblCustomerLotNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblShiftNo
        '
        Me.lblShiftNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblShiftNo.Location = New System.Drawing.Point(271, 72)
        Me.lblShiftNo.Name = "lblShiftNo"
        Me.lblShiftNo.Size = New System.Drawing.Size(64, 15)
        Me.lblShiftNo.TabIndex = 20
        Me.lblShiftNo.Text = "Shift No"
        Me.lblShiftNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblOPNo
        '
        Me.lblOPNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblOPNo.Location = New System.Drawing.Point(527, 72)
        Me.lblOPNo.Name = "lblOPNo"
        Me.lblOPNo.Size = New System.Drawing.Size(75, 15)
        Me.lblOPNo.TabIndex = 22
        Me.lblOPNo.Text = "OP No"
        Me.lblOPNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblEmployeeNo
        '
        Me.lblEmployeeNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblEmployeeNo.Location = New System.Drawing.Point(3, 72)
        Me.lblEmployeeNo.Name = "lblEmployeeNo"
        Me.lblEmployeeNo.Size = New System.Drawing.Size(80, 15)
        Me.lblEmployeeNo.TabIndex = 18
        Me.lblEmployeeNo.Text = "Employee No"
        Me.lblEmployeeNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblAreaNo
        '
        Me.lblAreaNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblAreaNo.Location = New System.Drawing.Point(527, 18)
        Me.lblAreaNo.Name = "lblAreaNo"
        Me.lblAreaNo.Size = New System.Drawing.Size(75, 15)
        Me.lblAreaNo.TabIndex = 4
        Me.lblAreaNo.Text = "Area No"
        Me.lblAreaNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblSysQty
        '
        Me.lblSysQty.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblSysQty.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblSysQty.Location = New System.Drawing.Point(791, 45)
        Me.lblSysQty.Name = "lblSysQty"
        Me.lblSysQty.Size = New System.Drawing.Size(64, 15)
        Me.lblSysQty.TabIndex = 15
        Me.lblSysQty.Text = "Sys Qty"
        Me.lblSysQty.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblCurQty
        '
        Me.lblCurQty.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblCurQty.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCurQty.Location = New System.Drawing.Point(791, 18)
        Me.lblCurQty.Name = "lblCurQty"
        Me.lblCurQty.Size = New System.Drawing.Size(64, 15)
        Me.lblCurQty.TabIndex = 6
        Me.lblCurQty.Text = "Cur Qty"
        Me.lblCurQty.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblLotNo
        '
        Me.lblLotNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblLotNo.Location = New System.Drawing.Point(3, 18)
        Me.lblLotNo.Name = "lblLotNo"
        Me.lblLotNo.Size = New System.Drawing.Size(80, 15)
        Me.lblLotNo.TabIndex = 0
        Me.lblLotNo.Text = "Lot No"
        Me.lblLotNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblProductNo
        '
        Me.lblProductNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblProductNo.Location = New System.Drawing.Point(527, 45)
        Me.lblProductNo.Name = "lblProductNo"
        Me.lblProductNo.Size = New System.Drawing.Size(75, 15)
        Me.lblProductNo.TabIndex = 13
        Me.lblProductNo.Text = "Product No"
        Me.lblProductNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtLotRecord
        '
        Me.txtLotRecord.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtLotRecord.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtLotRecord.Location = New System.Drawing.Point(96, 229)
        Me.txtLotRecord.Name = "txtLotRecord"
        Me.txtLotRecord.Size = New System.Drawing.Size(233, 64)
        Me.txtLotRecord.TabIndex = 6
        Me.txtLotRecord.Text = ""
        '
        'iugKeyIn
        '
        Me.iugKeyIn.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.iugKeyIn.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugKeyIn.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugKeyIn.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugKeyIn.Identity = "IMes"
        Me.iugKeyIn.IdentityForm = ""
        Me.iugKeyIn.LayOutFilePath = ""
        Me.iugKeyIn.Location = New System.Drawing.Point(8, 187)
        Me.iugKeyIn.Name = "iugKeyIn"
        Me.iugKeyIn.PrintFitWidthToPages = 0
        Me.iugKeyIn.PrintLandscape = True
        Me.iugKeyIn.PrintPageFooter = ""
        Me.iugKeyIn.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugKeyIn.PrintPageFooterHeight = 20
        Me.iugKeyIn.PrintPageHeader = ""
        Me.iugKeyIn.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugKeyIn.PrintPageHeaderHeight = 20
        Me.iugKeyIn.PrintZoom = 1.0R
        Me.iugKeyIn.Size = New System.Drawing.Size(643, 143)
        Me.iugKeyIn.TabIndex = 7
        Me.iugKeyIn.UserNo = "IMes"
        '
        'lblLotRecord
        '
        Me.lblLotRecord.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblLotRecord.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblLotRecord.Location = New System.Drawing.Point(27, 232)
        Me.lblLotRecord.Name = "lblLotRecord"
        Me.lblLotRecord.Size = New System.Drawing.Size(66, 16)
        Me.lblLotRecord.TabIndex = 5
        Me.lblLotRecord.Text = "Lot Record"
        Me.lblLotRecord.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        '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(925, 673)
        Me.btnClose.Name = "btnClose"
        Me.btnClose.Size = New System.Drawing.Size(80, 32)
        Me.btnClose.TabIndex = 12
        Me.btnClose.Text = "Close"
        '
        'btnConfirm
        '
        Me.btnConfirm.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnConfirm.Location = New System.Drawing.Point(839, 673)
        Me.btnConfirm.Name = "btnConfirm"
        Me.btnConfirm.Size = New System.Drawing.Size(80, 32)
        Me.btnConfirm.TabIndex = 11
        Me.btnConfirm.Text = "Confirm"
        '
        'iugMaterial
        '
        Me.iugMaterial.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.iugMaterial.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugMaterial.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugMaterial.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugMaterial.Identity = "IMes"
        Me.iugMaterial.IdentityForm = ""
        Me.iugMaterial.LayOutFilePath = ""
        Me.iugMaterial.Location = New System.Drawing.Point(5, 41)
        Me.iugMaterial.Name = "iugMaterial"
        Me.iugMaterial.PrintFitWidthToPages = 0
        Me.iugMaterial.PrintLandscape = True
        Me.iugMaterial.PrintPageFooter = ""
        Me.iugMaterial.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugMaterial.PrintPageFooterHeight = 20
        Me.iugMaterial.PrintPageHeader = ""
        Me.iugMaterial.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugMaterial.PrintPageHeaderHeight = 20
        Me.iugMaterial.PrintZoom = 1.0R
        Me.iugMaterial.Size = New System.Drawing.Size(643, 128)
        Me.iugMaterial.TabIndex = 6
        Me.iugMaterial.UserNo = "IMes"
        '
        'iugEquipment
        '
        Me.iugEquipment.Anchor = System.Windows.Forms.AnchorStyles.Left
        Me.iugEquipment.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugEquipment.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugEquipment.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugEquipment.Identity = "IMes"
        Me.iugEquipment.IdentityForm = ""
        Me.iugEquipment.LayOutFilePath = ""
        Me.iugEquipment.Location = New System.Drawing.Point(0, 0)
        Me.iugEquipment.Name = "iugEquipment"
        Me.iugEquipment.PrintFitWidthToPages = 0
        Me.iugEquipment.PrintLandscape = True
        Me.iugEquipment.PrintPageFooter = ""
        Me.iugEquipment.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugEquipment.PrintPageFooterHeight = 20
        Me.iugEquipment.PrintPageHeader = ""
        Me.iugEquipment.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugEquipment.PrintPageHeaderHeight = 20
        Me.iugEquipment.PrintZoom = 1.0R
        Me.iugEquipment.Size = New System.Drawing.Size(276, 137)
        Me.iugEquipment.TabIndex = 2
        Me.iugEquipment.UserNo = "IMes"
        '
        'iugAttrib
        '
        Me.iugAttrib.Dock = System.Windows.Forms.DockStyle.Fill
        Me.iugAttrib.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugAttrib.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugAttrib.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugAttrib.Identity = "IMes"
        Me.iugAttrib.IdentityForm = ""
        Me.iugAttrib.LayOutFilePath = ""
        Me.iugAttrib.Location = New System.Drawing.Point(0, 0)
        Me.iugAttrib.Name = "iugAttrib"
        Me.iugAttrib.PrintFitWidthToPages = 0
        Me.iugAttrib.PrintLandscape = True
        Me.iugAttrib.PrintPageFooter = ""
        Me.iugAttrib.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugAttrib.PrintPageFooterHeight = 20
        Me.iugAttrib.PrintPageHeader = ""
        Me.iugAttrib.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugAttrib.PrintPageHeaderHeight = 20
        Me.iugAttrib.PrintZoom = 1.0R
        Me.iugAttrib.Size = New System.Drawing.Size(340, 137)
        Me.iugAttrib.TabIndex = 1
        Me.iugAttrib.UserNo = "IMes"
        '
        'txtMaterialNo
        '
        Me.txtMaterialNo.Location = New System.Drawing.Point(77, 13)
        Me.txtMaterialNo.Name = "txtMaterialNo"
        Me.txtMaterialNo.Size = New System.Drawing.Size(145, 22)
        Me.txtMaterialNo.TabIndex = 1
        '
        'lblMaterialNo
        '
        Me.lblMaterialNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMaterialNo.Location = New System.Drawing.Point(7, 16)
        Me.lblMaterialNo.Name = "lblMaterialNo"
        Me.lblMaterialNo.Size = New System.Drawing.Size(65, 15)
        Me.lblMaterialNo.TabIndex = 0
        Me.lblMaterialNo.Text = "Material No"
        Me.lblMaterialNo.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'gbxMaterial
        '
        Me.gbxMaterial.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.gbxMaterial.Controls.Add(Me.btnKeyIn)
        Me.gbxMaterial.Controls.Add(Me.txtMaterialLotNo)
        Me.gbxMaterial.Controls.Add(Me.lblMaterialLotNo)
        Me.gbxMaterial.Controls.Add(Me.btnDel)
        Me.gbxMaterial.Controls.Add(Me.iugMaterial)
        Me.gbxMaterial.Controls.Add(Me.txtMaterialNo)
        Me.gbxMaterial.Controls.Add(Me.lblMaterialNo)
        Me.gbxMaterial.Location = New System.Drawing.Point(3, 4)
        Me.gbxMaterial.Name = "gbxMaterial"
        Me.gbxMaterial.Size = New System.Drawing.Size(653, 177)
        Me.gbxMaterial.TabIndex = 4
        Me.gbxMaterial.TabStop = False
        '
        'btnKeyIn
        '
        Me.btnKeyIn.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnKeyIn.Location = New System.Drawing.Point(580, 12)
        Me.btnKeyIn.Name = "btnKeyIn"
        Me.btnKeyIn.Size = New System.Drawing.Size(64, 24)
        Me.btnKeyIn.TabIndex = 4
        Me.btnKeyIn.Text = "Key In"
        '
        'txtMaterialLotNo
        '
        Me.txtMaterialLotNo.Location = New System.Drawing.Point(321, 13)
        Me.txtMaterialLotNo.Name = "txtMaterialLotNo"
        Me.txtMaterialLotNo.Size = New System.Drawing.Size(117, 22)
        Me.txtMaterialLotNo.TabIndex = 3
        '
        'lblMaterialLotNo
        '
        Me.lblMaterialLotNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMaterialLotNo.Location = New System.Drawing.Point(230, 16)
        Me.lblMaterialLotNo.Name = "lblMaterialLotNo"
        Me.lblMaterialLotNo.Size = New System.Drawing.Size(86, 15)
        Me.lblMaterialLotNo.TabIndex = 2
        Me.lblMaterialLotNo.Text = "Material Lot No"
        Me.lblMaterialLotNo.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        '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(579, 11)
        Me.btnDel.Name = "btnDel"
        Me.btnDel.Size = New System.Drawing.Size(64, 24)
        Me.btnDel.TabIndex = 5
        Me.btnDel.Text = "Del"
        Me.btnDel.Visible = False
        '
        'iugError
        '
        Me.iugError.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.iugError.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugError.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugError.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugError.Identity = "IMes"
        Me.iugError.IdentityForm = ""
        Me.iugError.LayOutFilePath = ""
        Me.iugError.Location = New System.Drawing.Point(6, 45)
        Me.iugError.Name = "iugError"
        Me.iugError.PrintFitWidthToPages = 0
        Me.iugError.PrintLandscape = True
        Me.iugError.PrintPageFooter = ""
        Me.iugError.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugError.PrintPageFooterHeight = 20
        Me.iugError.PrintPageHeader = ""
        Me.iugError.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugError.PrintPageHeaderHeight = 20
        Me.iugError.PrintZoom = 1.0R
        Me.iugError.Size = New System.Drawing.Size(323, 170)
        Me.iugError.TabIndex = 4
        Me.iugError.UserNo = "IMes"
        '
        'gbxError
        '
        Me.gbxError.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.gbxError.Controls.Add(Me.txtErrorQty)
        Me.gbxError.Controls.Add(Me.lblErrorQty)
        Me.gbxError.Controls.Add(Me.txtErrorNo)
        Me.gbxError.Controls.Add(Me.lblErrorNo)
        Me.gbxError.Controls.Add(Me.iugError)
        Me.gbxError.Location = New System.Drawing.Point(0, 0)
        Me.gbxError.Name = "gbxError"
        Me.gbxError.Size = New System.Drawing.Size(335, 223)
        Me.gbxError.TabIndex = 3
        Me.gbxError.TabStop = False
        '
        'txtErrorQty
        '
        Me.txtErrorQty.Location = New System.Drawing.Point(253, 12)
        Me.txtErrorQty.Name = "txtErrorQty"
        Me.txtErrorQty.Size = New System.Drawing.Size(76, 22)
        Me.txtErrorQty.TabIndex = 3
        '
        'lblErrorQty
        '
        Me.lblErrorQty.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblErrorQty.Location = New System.Drawing.Point(183, 16)
        Me.lblErrorQty.Name = "lblErrorQty"
        Me.lblErrorQty.Size = New System.Drawing.Size(64, 15)
        Me.lblErrorQty.TabIndex = 2
        Me.lblErrorQty.Text = "Error Qty"
        Me.lblErrorQty.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'txtErrorNo
        '
        Me.txtErrorNo.Location = New System.Drawing.Point(72, 13)
        Me.txtErrorNo.Name = "txtErrorNo"
        Me.txtErrorNo.Size = New System.Drawing.Size(105, 22)
        Me.txtErrorNo.TabIndex = 1
        '
        'lblErrorNo
        '
        Me.lblErrorNo.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblErrorNo.Location = New System.Drawing.Point(7, 16)
        Me.lblErrorNo.Name = "lblErrorNo"
        Me.lblErrorNo.Size = New System.Drawing.Size(60, 15)
        Me.lblErrorNo.TabIndex = 0
        Me.lblErrorNo.Text = "Error No"
        Me.lblErrorNo.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'dtpcheckouttime
        '
        Me.dtpcheckouttime.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.dtpcheckouttime.CustomFormat = "yyyy/MM/dd HH:mm:ss"
        Me.dtpcheckouttime.Format = System.Windows.Forms.DateTimePickerFormat.Custom
        Me.dtpcheckouttime.Location = New System.Drawing.Point(155, 680)
        Me.dtpcheckouttime.Name = "dtpcheckouttime"
        Me.dtpcheckouttime.Size = New System.Drawing.Size(128, 21)
        Me.dtpcheckouttime.TabIndex = 9
        '
        'lblupdcheckouttime
        '
        Me.lblupdcheckouttime.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblupdcheckouttime.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblupdcheckouttime.Location = New System.Drawing.Point(1, 683)
        Me.lblupdcheckouttime.Name = "lblupdcheckouttime"
        Me.lblupdcheckouttime.Size = New System.Drawing.Size(126, 18)
        Me.lblupdcheckouttime.TabIndex = 8
        Me.lblupdcheckouttime.Text = "Update CheckOut Time"
        '
        'btnMultiUser
        '
        Me.btnMultiUser.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnMultiUser.Location = New System.Drawing.Point(385, 675)
        Me.btnMultiUser.Name = "btnMultiUser"
        Me.btnMultiUser.Size = New System.Drawing.Size(80, 32)
        Me.btnMultiUser.TabIndex = 10
        Me.btnMultiUser.Text = "Multi User"
        Me.btnMultiUser.Visible = False
        '
        'btnOperator
        '
        Me.btnOperator.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnOperator.Location = New System.Drawing.Point(299, 675)
        Me.btnOperator.Name = "btnOperator"
        Me.btnOperator.Size = New System.Drawing.Size(80, 32)
        Me.btnOperator.TabIndex = 157
        Me.btnOperator.Text = "Operator"
        Me.btnOperator.Visible = False
        '
        'chkUpdCheckOutTime
        '
        Me.chkUpdCheckOutTime.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.chkUpdCheckOutTime.AutoSize = True
        Me.chkUpdCheckOutTime.Location = New System.Drawing.Point(133, 683)
        Me.chkUpdCheckOutTime.Name = "chkUpdCheckOutTime"
        Me.chkUpdCheckOutTime.Size = New System.Drawing.Size(15, 14)
        Me.chkUpdCheckOutTime.TabIndex = 158
        Me.chkUpdCheckOutTime.UseVisualStyleBackColor = True
        '
        'txtUnionProductNo
        '
        Me.txtUnionProductNo.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtUnionProductNo.Location = New System.Drawing.Point(96, 308)
        Me.txtUnionProductNo.Name = "txtUnionProductNo"
        Me.txtUnionProductNo.ReadOnly = True
        Me.txtUnionProductNo.Size = New System.Drawing.Size(151, 22)
        Me.txtUnionProductNo.TabIndex = 160
        '
        'txtUnionProductVersion
        '
        Me.txtUnionProductVersion.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtUnionProductVersion.Location = New System.Drawing.Point(258, 308)
        Me.txtUnionProductVersion.Name = "txtUnionProductVersion"
        Me.txtUnionProductVersion.ReadOnly = True
        Me.txtUnionProductVersion.Size = New System.Drawing.Size(41, 22)
        Me.txtUnionProductVersion.TabIndex = 3
        '
        'btnGetProduct
        '
        Me.btnGetProduct.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnGetProduct.Location = New System.Drawing.Point(303, 308)
        Me.btnGetProduct.Name = "btnGetProduct"
        Me.btnGetProduct.Size = New System.Drawing.Size(24, 24)
        Me.btnGetProduct.TabIndex = 161
        Me.btnGetProduct.Text = "..."
        '
        'txtUnionProductUnit
        '
        Me.txtUnionProductUnit.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtUnionProductUnit.Location = New System.Drawing.Point(348, 308)
        Me.txtUnionProductUnit.Name = "txtUnionProductUnit"
        Me.txtUnionProductUnit.ReadOnly = True
        Me.txtUnionProductUnit.Size = New System.Drawing.Size(41, 22)
        Me.txtUnionProductUnit.TabIndex = 162
        '
        'btnSWR
        '
        Me.btnSWR.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnSWR.Location = New System.Drawing.Point(658, 673)
        Me.btnSWR.Name = "btnSWR"
        Me.btnSWR.Size = New System.Drawing.Size(80, 32)
        Me.btnSWR.TabIndex = 163
        Me.btnSWR.Text = "SWR"
        '
        'chkUnionProductNo
        '
        Me.chkUnionProductNo.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.chkUnionProductNo.Location = New System.Drawing.Point(5, 311)
        Me.chkUnionProductNo.Name = "chkUnionProductNo"
        Me.chkUnionProductNo.Size = New System.Drawing.Size(99, 19)
        Me.chkUnionProductNo.TabIndex = 5
        Me.chkUnionProductNo.Text = "UnionProductNo"
        Me.chkUnionProductNo.UseVisualStyleBackColor = True
        '
        'btnBinStateAdjust
        '
        Me.btnBinStateAdjust.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnBinStateAdjust.Location = New System.Drawing.Point(744, 673)
        Me.btnBinStateAdjust.Name = "btnBinStateAdjust"
        Me.btnBinStateAdjust.Size = New System.Drawing.Size(89, 32)
        Me.btnBinStateAdjust.TabIndex = 165
        Me.btnBinStateAdjust.Text = "BinStateAdj"
        Me.btnBinStateAdjust.Visible = False
        '
        'uplAll
        '
        Me.uplAll.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)
        '
        'uplAll.ClientArea
        '
        Me.uplAll.ClientArea.Controls.Add(Me.uegMaterial_KeyIn2)
        Me.uplAll.ClientArea.Controls.Add(Me.uegAttrib_Equipment)
        Me.uplAll.ClientArea.Controls.Add(Me.uegLotInfo)
        Me.uplAll.Location = New System.Drawing.Point(0, 0)
        Me.uplAll.Name = "uplAll"
        Me.uplAll.Size = New System.Drawing.Size(1013, 667)
        Me.uplAll.TabIndex = 172
        '
        'uegMaterial_KeyIn2
        '
        Me.uegMaterial_KeyIn2.Controls.Add(Me.UltraExpandableGroupBoxPanel4)
        Me.uegMaterial_KeyIn2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.uegMaterial_KeyIn2.ExpandedSize = New System.Drawing.Size(1013, 357)
        Me.uegMaterial_KeyIn2.Location = New System.Drawing.Point(0, 310)
        Me.uegMaterial_KeyIn2.Name = "uegMaterial_KeyIn2"
        Me.uegMaterial_KeyIn2.Size = New System.Drawing.Size(1013, 357)
        Me.uegMaterial_KeyIn2.TabIndex = 163
        Me.uegMaterial_KeyIn2.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.Office2003
        '
        'UltraExpandableGroupBoxPanel4
        '
        Me.UltraExpandableGroupBoxPanel4.Controls.Add(Me.UltraPanel4)
        Me.UltraExpandableGroupBoxPanel4.Dock = System.Windows.Forms.DockStyle.Fill
        Me.UltraExpandableGroupBoxPanel4.Location = New System.Drawing.Point(2, 18)
        Me.UltraExpandableGroupBoxPanel4.Name = "UltraExpandableGroupBoxPanel4"
        Me.UltraExpandableGroupBoxPanel4.Size = New System.Drawing.Size(1009, 337)
        Me.UltraExpandableGroupBoxPanel4.TabIndex = 0
        '
        'UltraPanel4
        '
        '
        'UltraPanel4.ClientArea
        '
        Me.UltraPanel4.ClientArea.Controls.Add(Me.uplMaterial_KeyIn)
        Me.UltraPanel4.Dock = System.Windows.Forms.DockStyle.Fill
        Me.UltraPanel4.Location = New System.Drawing.Point(0, 0)
        Me.UltraPanel4.Name = "UltraPanel4"
        Me.UltraPanel4.Size = New System.Drawing.Size(1009, 337)
        Me.UltraPanel4.TabIndex = 0
        '
        'uplMaterial_KeyIn
        '
        '
        'uplMaterial_KeyIn.ClientArea
        '
        Me.uplMaterial_KeyIn.ClientArea.Controls.Add(Me.uplKeyIn)
        Me.uplMaterial_KeyIn.ClientArea.Controls.Add(Me.UltraSplitter2)
        Me.uplMaterial_KeyIn.ClientArea.Controls.Add(Me.uplMaterial)
        Me.uplMaterial_KeyIn.Dock = System.Windows.Forms.DockStyle.Fill
        Me.uplMaterial_KeyIn.Location = New System.Drawing.Point(0, 0)
        Me.uplMaterial_KeyIn.Name = "uplMaterial_KeyIn"
        Me.uplMaterial_KeyIn.Size = New System.Drawing.Size(1009, 337)
        Me.uplMaterial_KeyIn.TabIndex = 0
        '
        'uplKeyIn
        '
        '
        'uplKeyIn.ClientArea
        '
        Me.uplKeyIn.ClientArea.Controls.Add(Me.gbxMaterial)
        Me.uplKeyIn.ClientArea.Controls.Add(Me.iugKeyIn)
        Me.uplKeyIn.Dock = System.Windows.Forms.DockStyle.Fill
        Me.uplKeyIn.Location = New System.Drawing.Point(347, 0)
        Me.uplKeyIn.Name = "uplKeyIn"
        Me.uplKeyIn.Size = New System.Drawing.Size(662, 337)
        Me.uplKeyIn.TabIndex = 4
        '
        'UltraSplitter2
        '
        Me.UltraSplitter2.Location = New System.Drawing.Point(340, 0)
        Me.UltraSplitter2.Name = "UltraSplitter2"
        Me.UltraSplitter2.RestoreExtent = 479
        Me.UltraSplitter2.Size = New System.Drawing.Size(7, 337)
        Me.UltraSplitter2.TabIndex = 3
        '
        'uplMaterial
        '
        '
        'uplMaterial.ClientArea
        '
        Me.uplMaterial.ClientArea.Controls.Add(Me.gbxError)
        Me.uplMaterial.ClientArea.Controls.Add(Me.lblLotRecord)
        Me.uplMaterial.ClientArea.Controls.Add(Me.txtLotRecord)
        Me.uplMaterial.ClientArea.Controls.Add(Me.txtUnionProductUnit)
        Me.uplMaterial.ClientArea.Controls.Add(Me.txtUnionProductNo)
        Me.uplMaterial.ClientArea.Controls.Add(Me.btnGetProduct)
        Me.uplMaterial.ClientArea.Controls.Add(Me.chkUnionProductNo)
        Me.uplMaterial.ClientArea.Controls.Add(Me.txtUnionProductVersion)
        Me.uplMaterial.Dock = System.Windows.Forms.DockStyle.Left
        Me.uplMaterial.Location = New System.Drawing.Point(0, 0)
        Me.uplMaterial.Name = "uplMaterial"
        Me.uplMaterial.Size = New System.Drawing.Size(340, 337)
        Me.uplMaterial.TabIndex = 0
        '
        'uegAttrib_Equipment
        '
        Me.uegAttrib_Equipment.Controls.Add(Me.UltraExpandableGroupBoxPanel2)
        Me.uegAttrib_Equipment.Dock = System.Windows.Forms.DockStyle.Top
        Me.uegAttrib_Equipment.ExpandedSize = New System.Drawing.Size(1013, 157)
        Me.uegAttrib_Equipment.Location = New System.Drawing.Point(0, 153)
        Me.uegAttrib_Equipment.Name = "uegAttrib_Equipment"
        Me.uegAttrib_Equipment.Size = New System.Drawing.Size(1013, 157)
        Me.uegAttrib_Equipment.TabIndex = 162
        Me.uegAttrib_Equipment.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.Office2003
        '
        'UltraExpandableGroupBoxPanel2
        '
        Me.UltraExpandableGroupBoxPanel2.Controls.Add(Me.UltraPanel2)
        Me.UltraExpandableGroupBoxPanel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.UltraExpandableGroupBoxPanel2.Location = New System.Drawing.Point(2, 18)
        Me.UltraExpandableGroupBoxPanel2.Name = "UltraExpandableGroupBoxPanel2"
        Me.UltraExpandableGroupBoxPanel2.Size = New System.Drawing.Size(1009, 137)
        Me.UltraExpandableGroupBoxPanel2.TabIndex = 0
        '
        'UltraPanel2
        '
        '
        'UltraPanel2.ClientArea
        '
        Me.UltraPanel2.ClientArea.Controls.Add(Me.uplAttrib_Equipment)
        Me.UltraPanel2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.UltraPanel2.Location = New System.Drawing.Point(0, 0)
        Me.UltraPanel2.Name = "UltraPanel2"
        Me.UltraPanel2.Size = New System.Drawing.Size(1009, 137)
        Me.UltraPanel2.TabIndex = 0
        '
        'uplAttrib_Equipment
        '
        '
        'uplAttrib_Equipment.ClientArea
        '
        Me.uplAttrib_Equipment.ClientArea.Controls.Add(Me.uplEquipment)
        Me.uplAttrib_Equipment.ClientArea.Controls.Add(Me.UltraSplitter1)
        Me.uplAttrib_Equipment.ClientArea.Controls.Add(Me.uplAttrib)
        Me.uplAttrib_Equipment.Dock = System.Windows.Forms.DockStyle.Fill
        Me.uplAttrib_Equipment.Location = New System.Drawing.Point(0, 0)
        Me.uplAttrib_Equipment.Name = "uplAttrib_Equipment"
        Me.uplAttrib_Equipment.Size = New System.Drawing.Size(1009, 137)
        Me.uplAttrib_Equipment.TabIndex = 162
        '
        'uplEquipment
        '
        '
        'uplEquipment.ClientArea
        '
        Me.uplEquipment.ClientArea.Controls.Add(Me.iugStuInfo)
        Me.uplEquipment.ClientArea.Controls.Add(Me.iugEquipment)
        Me.uplEquipment.Dock = System.Windows.Forms.DockStyle.Fill
        Me.uplEquipment.Location = New System.Drawing.Point(347, 0)
        Me.uplEquipment.Name = "uplEquipment"
        Me.uplEquipment.Size = New System.Drawing.Size(662, 137)
        Me.uplEquipment.TabIndex = 1
        '
        'iugStuInfo
        '
        Me.iugStuInfo.Anchor = System.Windows.Forms.AnchorStyles.Right
        Me.iugStuInfo.EnterDirection = iMESUltraGrid.iMESUltraGridControl.EnterDirectionEnum.Down
        Me.iugStuInfo.GroupBoxPromptText = "Drag a column header here to group by that column."
        Me.iugStuInfo.GroupBoxTextForeColor = System.Drawing.Color.Red
        Me.iugStuInfo.Identity = "IMes"
        Me.iugStuInfo.IdentityForm = ""
        Me.iugStuInfo.LayOutFilePath = ""
        Me.iugStuInfo.Location = New System.Drawing.Point(277, 0)
        Me.iugStuInfo.Name = "iugStuInfo"
        Me.iugStuInfo.PrintFitWidthToPages = 0
        Me.iugStuInfo.PrintLandscape = True
        Me.iugStuInfo.PrintPageFooter = ""
        Me.iugStuInfo.PrintPageFooterHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugStuInfo.PrintPageFooterHeight = 20
        Me.iugStuInfo.PrintPageHeader = ""
        Me.iugStuInfo.PrintPageHeaderHAlign = Infragistics.Win.HAlign.[Default]
        Me.iugStuInfo.PrintPageHeaderHeight = 20
        Me.iugStuInfo.PrintZoom = 1.0R
        Me.iugStuInfo.Size = New System.Drawing.Size(376, 137)
        Me.iugStuInfo.TabIndex = 3
        Me.iugStuInfo.UserNo = "IMes"
        '
        'UltraSplitter1
        '
        Me.UltraSplitter1.Location = New System.Drawing.Point(340, 0)
        Me.UltraSplitter1.Name = "UltraSplitter1"
        Me.UltraSplitter1.RestoreExtent = 479
        Me.UltraSplitter1.Size = New System.Drawing.Size(7, 137)
        Me.UltraSplitter1.TabIndex = 1
        '
        'uplAttrib
        '
        '
        'uplAttrib.ClientArea
        '
        Me.uplAttrib.ClientArea.Controls.Add(Me.iugAttrib)
        Me.uplAttrib.Dock = System.Windows.Forms.DockStyle.Left
        Me.uplAttrib.Location = New System.Drawing.Point(0, 0)
        Me.uplAttrib.Name = "uplAttrib"
        Me.uplAttrib.Size = New System.Drawing.Size(340, 137)
        Me.uplAttrib.TabIndex = 0
        '
        'uegLotInfo
        '
        Me.uegLotInfo.Controls.Add(Me.UltraExpandableGroupBoxPanel1)
        Me.uegLotInfo.Dock = System.Windows.Forms.DockStyle.Top
        Me.uegLotInfo.ExpandedSize = New System.Drawing.Size(1013, 153)
        Me.uegLotInfo.Location = New System.Drawing.Point(0, 0)
        Me.uegLotInfo.Name = "uegLotInfo"
        Me.uegLotInfo.Size = New System.Drawing.Size(1013, 153)
        Me.uegLotInfo.TabIndex = 161
        Me.uegLotInfo.Text = "Lot Information"
        Me.uegLotInfo.ViewStyle = Infragistics.Win.Misc.GroupBoxViewStyle.Office2003
        '
        'UltraExpandableGroupBoxPanel1
        '
        Me.UltraExpandableGroupBoxPanel1.Controls.Add(Me.UltraPanel1)
        Me.UltraExpandableGroupBoxPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.UltraExpandableGroupBoxPanel1.Location = New System.Drawing.Point(2, 22)
        Me.UltraExpandableGroupBoxPanel1.Name = "UltraExpandableGroupBoxPanel1"
        Me.UltraExpandableGroupBoxPanel1.Size = New System.Drawing.Size(1009, 129)
        Me.UltraExpandableGroupBoxPanel1.TabIndex = 0
        '
        'UltraPanel1
        '
        '
        'UltraPanel1.ClientArea
        '
        Me.UltraPanel1.ClientArea.Controls.Add(Me.gbxLotInfo)
        Me.UltraPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.UltraPanel1.Location = New System.Drawing.Point(0, 0)
        Me.UltraPanel1.Name = "UltraPanel1"
        Me.UltraPanel1.Size = New System.Drawing.Size(1009, 129)
        Me.UltraPanel1.TabIndex = 0
        '
        'frmBR_L_CO_GEN
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(1008, 732)
        Me.Controls.Add(Me.uplAll)
        Me.Controls.Add(Me.btnBinStateAdjust)
        Me.Controls.Add(Me.btnSWR)
        Me.Controls.Add(Me.chkUpdCheckOutTime)
        Me.Controls.Add(Me.btnOperator)
        Me.Controls.Add(Me.btnMultiUser)
        Me.Controls.Add(Me.dtpcheckouttime)
        Me.Controls.Add(Me.lblupdcheckouttime)
        Me.Controls.Add(Me.btnClose)
        Me.Controls.Add(Me.btnConfirm)
        Me.Controls.Add(Me.SBar1)
        Me.Font = New System.Drawing.Font("Times New Roman", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.MinimizeBox = False
        Me.Name = "frmBR_L_CO_GEN"
        Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "General Check Out"
        CType(Me.SBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.SBarPanel2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.SBarPanel3, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.SBarPanel4, System.ComponentModel.ISupportInitialize).EndInit()
        Me.gbxLotInfo.ResumeLayout(False)
        Me.gbxLotInfo.PerformLayout()
        CType(Me.txtOPName, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtOPNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtProductNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtCustomerLotNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtMONo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtShiftNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtEmployeeNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtAreaNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtPriority, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtSysUnitNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtSysQty, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtCurUnitNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtCurQty, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtOPDescription, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtLotNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtMaterialNo, System.ComponentModel.ISupportInitialize).EndInit()
        Me.gbxMaterial.ResumeLayout(False)
        Me.gbxMaterial.PerformLayout()
        CType(Me.txtMaterialLotNo, System.ComponentModel.ISupportInitialize).EndInit()
        Me.gbxError.ResumeLayout(False)
        Me.gbxError.PerformLayout()
        CType(Me.txtErrorQty, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtErrorNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtUnionProductNo, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtUnionProductVersion, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.txtUnionProductUnit, System.ComponentModel.ISupportInitialize).EndInit()
        Me.uplAll.ClientArea.ResumeLayout(False)
        Me.uplAll.ResumeLayout(False)
        CType(Me.uegMaterial_KeyIn2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.uegMaterial_KeyIn2.ResumeLayout(False)
        Me.UltraExpandableGroupBoxPanel4.ResumeLayout(False)
        Me.UltraPanel4.ClientArea.ResumeLayout(False)
        Me.UltraPanel4.ResumeLayout(False)
        Me.uplMaterial_KeyIn.ClientArea.ResumeLayout(False)
        Me.uplMaterial_KeyIn.ResumeLayout(False)
        Me.uplKeyIn.ClientArea.ResumeLayout(False)
        Me.uplKeyIn.ResumeLayout(False)
        Me.uplMaterial.ClientArea.ResumeLayout(False)
        Me.uplMaterial.ClientArea.PerformLayout()
        Me.uplMaterial.ResumeLayout(False)
        CType(Me.uegAttrib_Equipment, System.ComponentModel.ISupportInitialize).EndInit()
        Me.uegAttrib_Equipment.ResumeLayout(False)
        Me.UltraExpandableGroupBoxPanel2.ResumeLayout(False)
        Me.UltraPanel2.ClientArea.ResumeLayout(False)
        Me.UltraPanel2.ResumeLayout(False)
        Me.uplAttrib_Equipment.ClientArea.ResumeLayout(False)
        Me.uplAttrib_Equipment.ResumeLayout(False)
        Me.uplEquipment.ClientArea.ResumeLayout(False)
        Me.uplEquipment.ResumeLayout(False)
        Me.uplAttrib.ClientArea.ResumeLayout(False)
        Me.uplAttrib.ResumeLayout(False)
        CType(Me.uegLotInfo, System.ComponentModel.ISupportInitialize).EndInit()
        Me.uegLotInfo.ResumeLayout(False)
        Me.UltraExpandableGroupBoxPanel1.ResumeLayout(False)
        Me.UltraPanel1.ClientArea.ResumeLayout(False)
        Me.UltraPanel1.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

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

        Dim editorSettings As New Infragistics.Win.UltraWinEditors.DefaultEditorOwnerSettings
        editorSettings.DataType = GetType(System.DateTime)
        editorSettings.MaskInput = "yyyy/mm/dd hh:mm:ss"
        editor = New Infragistics.Win.DateTimeEditor(New Infragistics.Win.UltraWinEditors.DefaultEditorOwner(editorSettings))

        vlMaterialLevel = COM_Utility.ValueListProvider.GetInstance.GetValueList("TBLWIPTEMP_MATERIAL", "MATERIALLEVEL")
        vlStuInfoIsSelected = COM_Utility.ValueListProvider.GetInstance.GetValueList("STUDENTINFO", "ISSELECTED")

        btnConfirm.Enabled = False
        btnMultiUser.Enabled = False
        Me.btnKeyIn.Visible = False

        '2017/11/06 KunYuan：變更結束加工時間checkbox預設不勾選
        chkUpdCheckOutTime.Checked = False

        If LotNo = defString Or UserId = defString Then
            iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200001", "[%LotNo%] [%or%] [%UserId%]"), MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub
        End If

        '2022/2/25 0104829: SDD211216_02-01 / HaveComponent、HaveLevel判斷抽換成共用function
        funGetLotStateIncludeData()


        Dim drSel As DataRow()

        Cursor.Current = Cursors.WaitCursor
        Call funLoadParameter("ChamberManage")
        ' 2016/01/05 YF, 左下角的時間預設為AP SERVER的時間
        Me.dtpcheckouttime.Value = funGetAPServerTime()

        '1.取出生產批資訊 --------------------------------------------------------------------------------------------
        If funLoadLotState() Then Exit Sub
        If dsWIP.Tables(tblLotState).Rows.Count = 0 Then
            iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200003", "[%LotNo%]"), MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub
        End If
        If funGetShift() Then Exit Sub
        If funLoadTemp_AttribJoinBasis() Then Exit Sub
        If funLoadTemp_Equipment() Then Exit Sub
        If funLoadTemp_Material() Then Exit Sub

        '[Mantis:86124]2021/01/19,Boyi,Add BinAssign
        '
        If HaveLevel Then
            Call funLoadSystemBin()
            Call funLoadGoodBinState()
            dtBinNew = dsWIP.Tables(strBinState).Clone 'copy schema to new datatable

            '93358: SDD210525_01-01/TriggerPS調整 93359: SDD210525_01-02/企業邏輯調整 若GoodBinState沒有資料 則不顯示KeyIn按鈕 Edison 21/06/01 
            If dsWIP.Tables(strBinState).Rows.Count > 0 Then
                btnBinStateAdjust.Visible = True
            End If
        End If

        txtLotNo.Text = LotNo
        txtEmployeeNo.Text = UserId
        Call funLotInfo_Show()

        '2.生產參數 ---------------------------------------------------------------------------------------------------
        If Not dsWIP.Tables(tblTAttrib) Is Nothing Then
            '轉換抽樣參數
            If funGetSampleData() Then Exit Sub
            dsWIP.Tables(tblTAttrib).DefaultView.RowFilter = "AttribSource <> 0 And AttribSource <> 1 And (AttribPhase = " & PhaseNo & " or AttribPhase = 99)"   'Source = Not KeyIn, Not Calculate ,Current and All Phase
            iugAttrib.iMESUltraGrid.DataSource = dsWIP.Tables(tblTAttrib).DefaultView
        End If

        '3.KeyIn Attrib ----------------------------------------------------------------------------------------------
        If Not dsWIP.Tables(tblTAttrib) Is Nothing Then
            dtKeyIn = New DataTable("KeyIn")
            dtKeyIn.DefaultView.AllowNew = False
            dtKeyIn.DefaultView.AllowDelete = False
            dtKeyIn.DefaultView.AllowEdit = True
            '建立KeyIn Table的欄位
            dtKeyIn.Columns.Add("AttribNo", System.Type.GetType("System.String"))
            dtKeyIn.Columns.Add("AttribName", System.Type.GetType("System.String"))
            dtKeyIn.Columns.Add("AttribValue", System.Type.GetType("System.String"))
            dtKeyIn.Columns.Add("AttribSequence", System.Type.GetType("System.Int32"))
            dtKeyIn.Columns.Add("InputType", System.Type.GetType("System.Int32"))
            dtKeyIn.Columns.Add("DataType", System.Type.GetType("System.Int32"))
            dtKeyIn.Columns.Add("ValueType", System.Type.GetType("System.Int32"))
            dtKeyIn.Columns.Add("QCItemNo", System.Type.GetType("System.String"))   '2015-12-18, Joe, Add

            '取出KeyIn Attrib
            For Each dr As DataRow In dsWIP.Tables(tblTAttrib).Rows
                '將資料存入KeyIn Table
                If dr("AttribSource") = 0 AndAlso (dr("AttribPhase") = PhaseNo OrElse dr("AttribPhase") = 99) Then
                    drAdd = dtKeyIn.NewRow()
                    drAdd("AttribNo") = dr("AttribNo")
                    drAdd("AttribName") = dr("AttribName")
                    drAdd("AttribSequence") = dr("AttribSequence")
                    drAdd("AttribValue") = dr("AttribValue")
                    drAdd("InputType") = dr("InputType")
                    drAdd("DataType") = dr("DataType")
                    drAdd("ValueType") = dr("ValueType")
                    drAdd("QCItemNo") = dr("QCItemNo")   '2015-12-18, Joe, Add
                    dtKeyIn.Rows.Add(drAdd)
                End If
            Next

            iugKeyIn.iMESUltraGrid.DataSource = dtKeyIn.DefaultView
        End If

        Call funLoadLotBasis()

        Call funLoadOEMOBasis()

        '4.Error
        If funLoadOPError() Then Exit Sub

        '5.OP Description
        If funGetOPDescription() Then Exit Sub

        If funLoadSYSParameter() Then Exit Sub

        '6.Initialize
        Call funInitialize()

        Call funLoadStuInfo()

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

        txtMaterialNo.Focus()     'Gary Lu 20131105:開啟畫面時游標在物料批號輸入文字方塊內

        '判斷系統參數EnableSWR_CICO 0:否 1:是
        strEnableSWR_CICO = "0"           '預設為否
        drSel = dsWIP.Tables(tblSYSParameter).Select("ParameterNo = 'EnableSWR_CICO'")
        If drSel.Length > 0 Then
            strEnableSWR_CICO = drSel(0)("ParameterValue").ToString
        End If

        btnSWR.Visible = False

        If strEnableSWR_CICO = "1" Then           '系統參數EnableSWR_CICO為1才需要顯示特殊生產需求

            '2019/02/12 Eric 無資料不顯示SWR視窗
            Call funLoadSWRJoinLog()
            If dsWIP.Tables(tblSWRJoinLog).Rows.Count > 0 Then
                blnShowSWR = True
            End If

            btnSWR.Visible = True

        End If

        '自動依CI刷入的料批給定標準用量
        Call funAutoSetMaterialLot()

        Cursor.Current = Cursors.Default
        Exit Sub


    End Sub

    Private Sub frmBR_L_CO_GEN_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

        If Not dsWIP.Tables(tblTMaterial) Is Nothing AndAlso dsWIP.Tables(tblTMaterial).Rows.Count > 0 Then
            txtMaterialNo.Focus()
        Else
            If iugKeyIn.iMESUltraGrid.Rows.Count > 0 Then
                'iugKeyIn.iMESUltraGrid.ActiveCell = iugKeyIn.iMESUltraGrid.Rows(0).Cells("AttribValue")
                iugKeyIn.iMESUltraGrid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode, False, False)
            End If
        End If

    End Sub

    Private Sub frmBR_L_CO_GEN_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        If Not dsWIP Is Nothing Then dsWIP.Dispose()
        If Not dtKeyIn Is Nothing Then dtKeyIn.Dispose()
        If Not dtMLot Is Nothing Then dtMLot.Dispose()
        '2019/12/17 OwenLiu, Mantis:0063698, 修正強制關閉企業邏輯，未正確執行ReverseTriggerOP的問題
        ' Call ExeReverseTriggerOP(UserId, LotNo, RevLotSerial, RevLotStamp)
        '2020/3/17,Ning,不啟用Reverse時的ReverseTriggerOP
        Call ExeReverseTriggerOP_NotUseUndo(UserId, LotNo, RevLotSerial, RevLotStamp)

    End Sub

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

#Region "Buttons"

    Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click

        Cursor.Current = Cursors.WaitCursor

        '1.基本檢查---------------------------------------------------------------------------------------------------
        Dim drSel(), drSelMTLLot(), drSelSeq() As DataRow
        Dim blnH_Scrap, blnH_Defect As Boolean
        Dim decScrapQty As Decimal = 0
        Dim decDefectQty As Decimal = 0
        Dim decLossQty As Decimal = 0
        Dim decGoodQty As Decimal = 0
        Dim decT_ScrapQty As Decimal = 0
        Dim decT_DefectQty As Decimal = 0
        Dim decBinQty_Sum As Decimal = 0
        Dim strNewBin As String = defString
        Dim bBinNew As Boolean = False
        Dim i As Integer

        drSel = dtKeyIn.Select("AttribNo = 'ScrapQty'")
        If drSel.Length = 0 Then
            blnH_Scrap = False  '沒有定義ScrapQty
        Else
            blnH_Scrap = True   '有定義ScrapQty
            If IsNumeric(drSel(0)("AttribValue")) Then
                decScrapQty = drSel(0)("AttribValue")
            Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%ScrapQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If
        End If
        drSel = dtKeyIn.Select("AttribNo = 'DefectQty'")
        If drSel.Length = 0 Then
            blnH_Defect = False '沒有定義DefectQty
        Else
            blnH_Defect = True  '有定義DefectQty
            If IsNumeric(drSel(0)("AttribValue")) Then
                decDefectQty = drSel(0)("AttribValue")
            Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%DefectQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If
        End If
        drSel = dtKeyIn.Select("AttribNo = 'GoodQty'")
        If drSel.Length > 0 Then
            If IsNumeric(drSel(0)("AttribValue")) Then
                decGoodQty = drSel(0)("AttribValue")

                If CDec(drSel(0)("AttribValue")) < 0 Then  '輸入的值需要大於或等於0
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200016", "[%GoodQty%] [%MUST BE GREATER THAN OR EQUAL TO%] 0 !!"), MsgBoxStyle.Exclamation, Me.Text)
                    Exit Sub
                End If
            Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%GoodQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If
        End If

        drSel = dtKeyIn.Select("AttribNo = 'LossQty'")
        If drSel.Length <> 0 Then
            If IsNumeric(drSel(0)("AttribValue")) Then
                decLossQty = drSel(0)("AttribValue")
            End If
        End If

        '不良原因輸入檢查
        If blnH_Scrap Then
            '計算總不良數
            drSel = dsWIP.Tables(tblOPError).Select("ReasonType=0 And CheckFlag=" & True)
            For i = 0 To drSel.Length - 1
                If drSel(i)("ErrorQty") <= 0 Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200015", "[%ErrorNo%]:" & drSel(i)("ErrorNo") & ",[%ErrorQty%] <0 !!"), MsgBoxStyle.Exclamation, Me.Text)
                    Exit Sub
                End If
                decT_ScrapQty = decT_ScrapQty + drSel(i)("ErrorQty")
            Next
            If decScrapQty <> decT_ScrapQty Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-203085", "[%ScrapQty%] [%IS NOT EQUAL TO%] [%TOTAL SCRAP REASONN QTY%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If
        End If

        '缺點原因輸入檢查
        If blnH_Defect Then
            '計算總缺點數
            drSel = dsWIP.Tables(tblOPError).Select("ReasonType=1 And CheckFlag=" & True)
            For i = 0 To drSel.Length - 1
                If drSel(i)("ErrorQty") <= 0 Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200015", "[%ErrorNo%]:" & drSel(i)("ErrorNo") & ",[%ErrorQty%] [%IS LESS THAN%] 0"), MsgBoxStyle.Exclamation, Me.Text)
                    Exit Sub
                End If
                decT_DefectQty = decT_DefectQty + drSel(i)("ErrorQty")
            Next
            If decDefectQty <> decT_DefectQty Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-203085", "[%DefectQty%] [%IS NOT EQUAL TO%] [%TOTAL DEFECT REASON QTY%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If
        End If

        Dim NewBinQty_Sun As Integer = 0

        '[Mantis:86124]2021/01/19,Boyi,Check BinAssign
        '93358: SDD210525_01-01/TriggerPS調整 93359: SDD210525_01-02/企業邏輯調整 若GoodBinState沒有資料 則不卡控 Edison 21/06/01 
        If HaveLevel AndAlso iGoodBinStateQty <> 0 Then

            If (CInt(decGoodQty) <> iGoodBinStateQty) Then
                bBinNew = True
                If dtBinNew.Rows.Count > 0 Then
                    '0111211: [49-1]扫脚_check-out_bin分布调整
                    '原卡控:比較最後bin分布數量是否=BR介面上的curQty
                    '移除此卡控。新邏輯:點選按鈕'bin分布調整'後,將'最終bin分布之總和'回壓至GoodQty
                    'For Each drTemp As DataRow In dsWIP.Tables(strSysBin).Rows
                    '    NewBinQty_Sun += CInt(dtBinNew.Rows(0)(drTemp("BinNo").ToString))
                    'Next
                    'If (NewBinQty_Sun <> decGoodQty) Then
                    '    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200060", "[%BinStateAdjust Qty is not equal GoodQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                    '    Exit Sub
                    'End If
                Else
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200005", "[%Please Assign BinState%]"), MsgBoxStyle.Exclamation, Me.Text)
                    Exit Sub
                End If
            Else
                bBinNew = False
            End If
            '0111211: [49-1]扫脚_check-out_bin分布调整
            '介面上的良品數與損壞數之總和,必須=curQty
            If decGoodQty + decScrapQty + CInt(decLossQty) <> CInt(txtCurQty.Text) Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200015", "[%Sum of GoodQty and ScrapQty%]: " & decGoodQty + decScrapQty & " [%NOTEQUALTO%][%CurQty%]: " & txtCurQty.Text & ""), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If
        End If


        '2.格式化資料Attrib--------------------------------------------------------------------------------------------
        Dim strAttrib As String = ""
        Dim strTemp As String

        If Not dsWIP.Tables(tblTAttrib) Is Nothing Then
            'Temp:Attrib
            'dsWIP.Tables(tblTAttrib).DefaultView.RowFilter = "Not (AttribPhase = " & PhaseNo & " And AttribSource = 0)"  '所有Attrib,除了Current Phase KeyIn
            'BR只處理CurPhase & AllPhase的Attrib(不包含KeyIn,KeyIn於後處理),其他非本Phase不可更動.
            dsWIP.Tables(tblTAttrib).DefaultView.RowFilter = "(AttribPhase = " & PhaseNo & " or AttribPhase = 99) And AttribSource <> 0"
            For i = 0 To dsWIP.Tables(tblTAttrib).DefaultView.Count - 1
                strTemp = CombineXMLValue("attribno", CInput(dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribNo"))) &
                          CombineXMLValue("attribtype", dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribType")) &
                          CombineXMLValue("attribsequence", dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribSequence")) &
                          CombineXMLValue("attribsource", dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribSource")) &
                          CombineXMLValue("attribphase", dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribPhase")) &
                          CombineXMLValue("savetolotpropertyno", CInput(dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("SaveToLotPropertyNo")))
                If IsDBNull(dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribValue")) Then
                    strTemp += CombineXMLValue("attribvalue", "")
                Else
                    strTemp += CombineXMLValue("attribvalue", CInput(dsWIP.Tables(tblTAttrib).DefaultView.Item(i)("AttribValue")))
                End If
                strAttrib += CombineXMLValueTag(strTemp)
            Next
            '還原顯示
            dsWIP.Tables(tblTAttrib).DefaultView.RowFilter = "AttribSource <> 0 And AttribSource <> 1 And (AttribPhase = " & PhaseNo & " or AttribPhase = 99)"    'Source = Not KeyIn, Not Calculate ,Current and All phase

            'Temp:Attrib_KeyIn
            For i = 0 To dtKeyIn.Rows.Count - 1
                If IsDBNull(dtKeyIn.Rows(i)("AttribValue")) = True Then
                    dtKeyIn.Rows(i)("AttribValue") = ""
                End If
                'R1102001 改由ChkControlRule時才判斷 By Acer 2011/02/21
                'If dtKeyIn.Rows(i)("AttribValue") = "" Then
                '    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200001", "[%AttribValue%] of [%AttribNo%]:" & dtKeyIn.Rows(i)("AttribNo") & " is empty!!"), MsgBoxStyle.Exclamation, Me.Text)
                '    GoTo lblExitProcedure
                'End If

                drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo='" & dtKeyIn.Rows(i)("AttribNo") & "'")
                If drSel.Length = 0 Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-203010", "[%AttribNo%]:" & dtKeyIn.Rows(i)("AttribNo")), MsgBoxStyle.Exclamation, Me.Text)
                    GoTo lblExitProcedure
                Else
                    strTemp = CombineXMLValue("attribno", CInput(dtKeyIn.Rows(i)("AttribNo"))) &
                            CombineXMLValue("attribtype", drSel(0)("AttribType")) &
                            CombineXMLValue("attribsequence", drSel(0)("AttribSequence")) &
                            CombineXMLValue("attribsource", drSel(0)("AttribSource")) &
                            CombineXMLValue("attribphase", drSel(0)("AttribPhase")) &
                            CombineXMLValue("attribvalue", CInput(dtKeyIn.Rows(i)("AttribValue"))) &
                            CombineXMLValue("savetolotpropertyno", CInput(drSel(0)("SaveToLotPropertyNo")))
                    '2015-12-18, Joe, Add QCItemNo
                    If IsDBNull(drSel(0)("QCItemNo")) Then
                        strTemp += CombineXMLValue("qcitemno", "")
                    Else
                        strTemp += CombineXMLValue("qcitemno", CInput(drSel(0)("QCItemNo")))
                    End If
                    strAttrib += CombineXMLValueTag(strTemp)
                End If
            Next
        End If

        '3.格式化資料Equipment-----------------------------------------------------------------------------------------------
        Dim strEquipment As String = ""
        Dim strEquipmentChamber As String = ""
        If Not dsWIP.Tables(tblTEquipment) Is Nothing Then
            For i = 0 To dsWIP.Tables(tblTEquipment).Rows.Count - 1
                strEquipment += CombineXMLValueTag(CombineXMLValue("equipmentno", CInput(dsWIP.Tables(tblTEquipment).Rows(i)("EquipmentNo"))))
            Next
        End If
        If Not dsWIP.Tables("Chamber") Is Nothing Then
            For Each dr As DataRow In dsWIP.Tables("Chamber").Rows
                strEquipmentChamber += CombineXMLValueTag(
                        CombineXMLValue("equipmentno", CInput(dr("EquipmentNo"))) &
                        CombineXMLValue("belongequipmentno", dr("BelongEquipmentNo")))
            Next
        End If

        '4.格式化資料Material-----------------------------------------------------------------------------------------------
        Dim strMaterial As String = ""
        Dim strMaterialExeCO As String = ""
        Dim strMaterialLot As String = ""
        Dim dtJoin As New DataTable   'Join兩個table
        Dim dtMaterialLotNo As New DataTable
        Dim drData As DataRow
        Dim drSelect, drSub As DataRow()

        If (Not dsWIP.Tables(tblTMaterial) Is Nothing) AndAlso (dsWIP.Tables(tblTMaterial).Rows.Count > 0) Then

            '新建一Table,彙整主物料及其替代料(合併dsWIP.Tables(tblTMaterial)和dtMLot)
            dtJoin = dsWIP.Tables(tblTMaterial).Copy
            '新增OrgMaterialNo,紀錄原來的主物料用
            Dim colOrgMaterialNo As New DataColumn With {
                .ColumnName = "OrgMaterialNo",
                .DataType = System.Type.GetType("System.String"),
                .DefaultValue = 0,
                .AllowDBNull = False
            }
            dtJoin.Columns.Add(colOrgMaterialNo)

            '紀錄原來的主物料
            For i = 0 To dtJoin.Rows.Count - 1
                dtJoin.Rows(i)("OrgMaterialNo") = dtJoin.Rows(i)("MaterialNo")
            Next

            For i = 0 To dtMLot.Rows.Count - 1
                drSelect = dtJoin.Select("MaterialNo='" & dtMLot.Rows(i)("SubstituteMaterialNo") & "' And OrgMaterialNo='" & dtMLot.Rows(i)("MaterialNo") & "'")
                If drSelect.Length > 0 Then
                    drSub = dtMLot.Select("SubstituteMaterialNo='" & drSelect(0)("MaterialNo") & "'")
                    Dim intSumUseQty As Decimal = 0 '使用數量加總
                    For j = 0 To drSub.Length - 1
                        intSumUseQty = intSumUseQty + drSub(j)("UseQty")
                    Next
                    drSelect(0)("UseQty") = intSumUseQty
                Else
                    drSelect = dtJoin.Select("MaterialNo='" & dtMLot.Rows(i)("MaterialNo") & "'")

                    '如果只有選取替代料而無選取主料,要將主料的UseQty設為0
                    drSub = dtMLot.Select("SubstituteMaterialNo='" & drSelect(0)("MaterialNo") & "' And MaterialNo='" & drSelect(0)("OrgMaterialNo") & "'")
                    If drSub.Length = 0 Then drSelect(0)("UseQty") = 0

                    drData = dtJoin.NewRow()
                    drData("OrgMaterialNo") = dtMLot.Rows(i)("MaterialNo")             '紀錄原來的主物料
                    drData("MaterialNo") = dtMLot.Rows(i)("SubstituteMaterialNo")   '把MaterialNo替換成SubstituteMaterialNo
                    drData("MaterialType") = dtMLot.Rows(i)("SubstituteMaterialType")
                    drData("MaterialLevelShow") = dtMLot.Rows(i)("SubstituteMaterialLevel")
                    drData("UseQty") = dtMLot.Rows(i)("UseQty")
                    drData("CheckLotNo") = dtMLot.Rows(i)("CheckLotNo")

                    '物料WIP INV投料點為2，半成品WIP INV投料點為4
                    '因用料清單是紀錄主料的投料點如果主料與替代料的物料位階不同，則投料點需替換。
                    If drSelect(0)("MaterialLevelShow") = 0 Then
                        If dtMLot.Rows(i)("SubstituteMaterialLevel") = 1 Then
                            If drSelect(0)("PutInPlaceType") = 2 Then
                                drData("PutInPlaceType") = 4
                            Else
                                drData("PutInPlaceType") = drSelect(0)("PutInPlaceType")
                            End If
                        Else
                            drData("PutInPlaceType") = drSelect(0)("PutInPlaceType")
                        End If
                    Else
                        If dtMLot.Rows(i)("SubstituteMaterialLevel") = 0 Then
                            If drSelect(0)("PutInPlaceType") = 4 Then
                                drData("PutInPlaceType") = 2
                            Else
                                drData("PutInPlaceType") = drSelect(0)("PutInPlaceType")
                            End If
                        Else
                            drData("PutInPlaceType") = drSelect(0)("PutInPlaceType")
                        End If
                    End If
                    drData("StdQty") = dtMLot.Rows(i)("SubstituteStdQty")
                    drData("DecreaseRate") = drSelect(0)("DecreaseRate")
                    drData("UnitNo") = drSelect(0)("UnitNo")
                    dtJoin.Rows.Add(drData)
                End If
            Next

            For Each drRow As DataRow In dsWIP.Tables(tblTMaterial).Rows
                If drRow("UseQty") = 0 Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200017", "[%MaterialNo%]: " & drRow("MaterialNo") & ", [%USEQTY%] [%MUST BE GREATER THAN%] 0"), MsgBoxStyle.Exclamation, Me.Text)
                    GoTo lblExitProcedure
                End If
            Next

            '傳入匯整後的資料
            For i = 0 To dtJoin.Rows.Count - 1
                If dtJoin.Rows(i)("UseQty") > 0 Then     '過濾UseQty為零的
                    strMaterial += CombineXMLValueTag(
                        CombineXMLValue("orgmaterialno", CInput(dtJoin.Rows(i)("OrgMaterialNo"))) &
                        CombineXMLValue("materialno", CInput(dtJoin.Rows(i)("MaterialNo"))) &
                        CombineXMLValue("materialtype", CInput(dtJoin.Rows(i)("MaterialType"))) &
                        CombineXMLValue("materiallevel", dtJoin.Rows(i)("MaterialLevelShow")) &
                        CombineXMLValue("useqty", dtJoin.Rows(i)("UseQty")) &
                        CombineXMLValue("checklotno", CInput(dtJoin.Rows(i)("CheckLotNo"))) &
                        CombineXMLValue("putinplacetype", dtJoin.Rows(i)("PutInPlaceType")) &
                        CombineXMLValue("stdqty", dtJoin.Rows(i)("StdQty")) &
                        CombineXMLValue("decreaserate", dtJoin.Rows(i)("DecreaseRate")) &
                        CombineXMLValue("unitno", CInput(dtJoin.Rows(i)("UnitNo"))))
                End If
            Next

            '因OrgMaterialNo在作Exe_CheckOut時不使用，Exe_CheckOut所使用的物料用量資料先合併
            Dim dtMaterialNo As New DataTable
            Dim drAddMNo As DataRow
            Dim drSelMNo As DataRow()
            dtMaterialNo.Columns.Add("MaterialNo", System.Type.GetType("System.String"))
            dtMaterialNo.Columns.Add("MaterialType", System.Type.GetType("System.String"))
            dtMaterialNo.Columns.Add("MaterialLevel", System.Type.GetType("System.String"))
            dtMaterialNo.Columns.Add("UseQty", System.Type.GetType("System.Decimal"))
            dtMaterialNo.Columns.Add("CheckLotNo", System.Type.GetType("System.Int16"))
            dtMaterialNo.Columns.Add("PutInPlaceType", System.Type.GetType("System.Int16"))
            dtMaterialNo.Columns.Add("StdQty", System.Type.GetType("System.Decimal"))
            dtMaterialNo.Columns.Add("DecreaseRate", System.Type.GetType("System.Decimal"))
            dtMaterialNo.Columns.Add("UnitNo", System.Type.GetType("System.String"))
            For i = 0 To dtJoin.Rows.Count - 1
                '過濾UseQty為零的
                If dtJoin.Rows(i)("UseQty") > 0 Then
                    drSelMNo = dtMaterialNo.Select("MaterialNo = '" & dtJoin.Rows(i)("MaterialNo") & "'")
                    If drSelMNo.Length = 0 Then
                        drAddMNo = dtMaterialNo.NewRow
                        drAddMNo("MaterialNo") = dtJoin.Rows(i)("MaterialNo")
                        drAddMNo("MaterialType") = dtJoin.Rows(i)("MaterialType")
                        drAddMNo("MaterialLevel") = dtJoin.Rows(i)("MaterialLevelShow")
                        drAddMNo("UseQty") = dtJoin.Rows(i)("UseQty")
                        drAddMNo("CheckLotNo") = dtJoin.Rows(i)("CheckLotNo")
                        drAddMNo("PutInPlaceType") = dtJoin.Rows(i)("PutInPlaceType")
                        drAddMNo("StdQty") = dtJoin.Rows(i)("StdQty")
                        drAddMNo("DecreaseRate") = dtJoin.Rows(i)("DecreaseRate")
                        drAddMNo("UnitNo") = dtJoin.Rows(i)("UnitNo")
                        dtMaterialNo.Rows.Add(drAddMNo)
                    Else
                        drSelMNo(0)("UseQty") += dtJoin.Rows(i)("UseQty")
                        drSelMNo(0)("StdQty") += dtJoin.Rows(i)("StdQty")
                        drSelMNo(0)("DecreaseRate") = (drSelect(0)("DecreaseRate") + dtJoin.Rows(i)("DecreaseRate")) / 2
                    End If
                End If
            Next

            '執行Exe_CheckOut與物料總用量檢查時所傳入的strMaterial
            For i = 0 To dtMaterialNo.Rows.Count - 1
                strMaterialExeCO += CombineXMLValueTag(
                                    CombineXMLValue("materialno", CInput(dtMaterialNo.Rows(i)("MaterialNo"))) &
                                    CombineXMLValue("materialtype", CInput(dtMaterialNo.Rows(i)("MaterialType"))) &
                                    CombineXMLValue("materiallevel", dtMaterialNo.Rows(i)("MaterialLevel")) &
                                    CombineXMLValue("useqty", dtMaterialNo.Rows(i)("UseQty")) &
                                    CombineXMLValue("checklotno", CInput(dtMaterialNo.Rows(i)("CheckLotNo"))) &
                                    CombineXMLValue("putinplacetype", dtMaterialNo.Rows(i)("PutInPlaceType")) &
                                    CombineXMLValue("stdqty", dtMaterialNo.Rows(i)("StdQty")) &
                                    CombineXMLValue("decreaserate", dtMaterialNo.Rows(i)("DecreaseRate")) &
                                    CombineXMLValue("unitno", CInput(dtMaterialNo.Rows(i)("UnitNo"))))
            Next

            '------------------------------------------物料料批資訊strMaterialLot---------------------------------------------
            '因替代料有可能相同，故相同的替代料料批要合併
            Dim drAddMLotNo As DataRow
            Dim drSelMLotNo As DataRow()
            dtMaterialLotNo.Columns.Add("EquipmentNo", System.Type.GetType("System.String"))
            dtMaterialLotNo.Columns.Add("MaterialNo", System.Type.GetType("System.String"))
            dtMaterialLotNo.Columns.Add("MaterialLotNo", System.Type.GetType("System.String"))
            dtMaterialLotNo.Columns.Add("UseQty", System.Type.GetType("System.Decimal"))
            ' 2016/10/26 YF, 設備用料管理替代料不用合併, 需依主料&替代料來判斷扣料
            dtMaterialLotNo.Columns.Add("OrgMaterialNo", System.Type.GetType("System.String"))

            For i = 0 To dtMLot.Rows.Count - 1

                If (dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString = "1") Then
                    ' 2016/10/26 YF, 設備用料管理
                    drAddMLotNo = dtMaterialLotNo.NewRow
                    drAddMLotNo("EquipmentNo") = dtMLot.Rows(i)("EquipmentNo")
                    drAddMLotNo("MaterialNo") = dtMLot.Rows(i)("SubstituteMaterialNo")
                    drAddMLotNo("OrgMaterialNo") = dtMLot.Rows(i)("MaterialNo")
                    drAddMLotNo("MaterialLotNo") = dtMLot.Rows(i)("MaterialLotNo")
                    drAddMLotNo("UseQty") = dtMLot.Rows(i)("UseQty")
                    dtMaterialLotNo.Rows.Add(drAddMLotNo)
                Else
                    drSelMLotNo = dtMaterialLotNo.Select("MaterialNo = '" & dtMLot.Rows(i)("SubstituteMaterialNo") & "' And MaterialLotNo ='" & dtMLot.Rows(i)("MaterialLotNo") & "'")
                    If drSelMLotNo.Length = 0 Then
                        drAddMLotNo = dtMaterialLotNo.NewRow
                        drAddMLotNo("EquipmentNo") = dtMLot.Rows(i)("EquipmentNo")
                        drAddMLotNo("MaterialNo") = dtMLot.Rows(i)("SubstituteMaterialNo")
                        drAddMLotNo("OrgMaterialNo") = dtMLot.Rows(i)("MaterialNo")
                        drAddMLotNo("MaterialLotNo") = dtMLot.Rows(i)("MaterialLotNo")
                        drAddMLotNo("UseQty") = dtMLot.Rows(i)("UseQty")
                        dtMaterialLotNo.Rows.Add(drAddMLotNo)
                    Else
                        drSelMLotNo(0)("UseQty") += dtMLot.Rows(i)("UseQty")
                    End If
                End If
            Next

            For i = 0 To dtMaterialLotNo.Rows.Count - 1
                If dtMaterialLotNo.Rows(i)("UseQty") > 0 Then
                    strMaterialLot += CombineXMLValueTag(
                                CombineXMLValue("materialno", CInput(dtMaterialLotNo.Rows(i)("MaterialNo"))) &
                                CombineXMLValue("orgmaterialno", CInput(dtMaterialLotNo.Rows(i)("OrgMaterialNo").ToString)) &
                                CombineXMLValue("materiallotno", CInput(dtMaterialLotNo.Rows(i)("MaterialLotNo"))) &
                                CombineXMLValue("qty", dtMaterialLotNo.Rows(i)("UseQty")) &
                                CombineXMLValue("equipmentno", CInput(dtMaterialLotNo.Rows(i)("EquipmentNo"))))
                End If
            Next
        End If

        '5.格式化不良原因-------------------------------------------------------------------------------------------------
        Dim strError As String = ""

        drSel = dsWIP.Tables(tblOPError).Select("CheckFlag=" & True)
        For i = 0 To drSel.Length - 1
            strError += CombineXMLValueTag(
                       CombineXMLValue("errorno", CInput(drSel(i)("ErrorNo"))) &
                       CombineXMLValue("errorqty", drSel(i)("ErrorQty")) &
                       CombineXMLValue("errorlevel", drSel(i)("ReasonLevel")))
        Next

        '聯產品有勾起則必需有聯產品資料
        Dim blnPRDChgDetail As Boolean = False

        If chkUnionProductNo.Checked Then
            If txtUnionProductNo.Text = "" Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200001", "[%UnionProductNo%]"), MsgBoxStyle.Exclamation, Me.Text)
                GoTo lblExitProcedure
            End If
            '若為新模式變更, 但此BR不為作業站最後一個BR時, 需提示不可變更聯產品
            drSel = dsWIP.Tables(tblSYSParameter).Select("ParameterNo = 'ProductChangeUpdDetail'")
            If drSel.Length > 0 Then
                If drSel(0)("ParameterValue").ToString = "1" Then
                    blnPRDChgDetail = True
                End If
            End If
        End If

        '6.檢查是否允許執行 ----------------------------------------------------------------------------------------------
        If ChkLotStamp(LotNo, UserId, dsWIP.Tables(tblLotState).Rows(0)("LotStamp")) < 0 Then GoTo lblExitProcedure


        Dim strMsg As String

        '8.Control Rule Check --------------------------------------------------------------------------------------------
        Dim strLinkName As String
        Dim strMailGroupNo As String = ""
        Dim strRuleNo As String = defString
        Dim intERFType As Integer = defInteger
        Dim dsTestValue As DataSet
        Dim strERFMsg As String
        Dim strHoldLotNo As String = defString

        If ChkControlRule(LotNo, UserId, dsWIP.Tables(tblLotState).Rows(0)("LotStamp"),
            strAttrib, strLinkName, strMsg, strRuleNo, intERFType, strMailGroupNo, strError, , , dsTestValue) < 0 Then GoTo lblExitProcedure

        '2015-12-07, Joe, Check SPC Contorl
        If funChkSPCControl_Var(LotNo, strAttrib, dsTestValue, strLinkName, intERFType, strERFMsg) < 0 Then GoTo lblExitProcedure
        strERFMsg = ChgTranslateErrorMsg(strERFMsg)

        '7.ChkMaterial---------------------------------------------------------------------------------------------
        '2022/8/23,Ning, 117535: 厦门云天--生产批进站后设备故障再修复，出站报错, 無用料資訊不需查核存量
        If Not dsWIP.Tables(tblTMaterial) Is Nothing AndAlso dsWIP.Tables(tblTMaterial).Rows.Count > 0 Then
            If funCheckMTLForBR(dtMLot.Copy, strLinkName, intERFType, strRuleNo) = False Then
                GoTo lblExitProcedure
            End If
        End If

        '若需變更明細, 則需檢查此BR是否為此作業站最後一個BR
        If chkUnionProductNo.Checked AndAlso blnPRDChgDetail = True Then
            If funChkLastBR(strLinkName) = False Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200015", "[%Current BR is not the last BR in OP, cannot change Product%]!"), MsgBoxStyle.Exclamation, Me.Text)
                GoTo lblExitProcedure
            End If
        End If

        '9.Execute CheckOut -----------------------------------------------------------------------------------------------
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", CInput(LotNo), "")
        strParameter += CombineXMLParameter("linkname", "LinkName", "String", CInput(strLinkName), "")
        strParameter += CombineXMLParameter("lotstamp", "LotStamp", "Decimal", dsWIP.Tables(tblLotState).Rows(0)("LotStamp"), "")
        strParameter += CombineXMLParameter("shiftno", "ShiftNo", "String", CInput(txtShiftNo.Text), "")
        'strParameter += CombineXMLParameter("checkouttime", "CheckOutTime", "String", dtpcheckouttime.Value.ToString("yyyy/MM/dd HH:mm:ss"), "")   '2017/11/06 mark by KunYuan：移至下方處理
        strParameter += CombineXMLParameterMultiValue("attrib", "Attrib", "String", strAttrib, "")
        strParameter += CombineXMLParameterMultiValue("equipment", "Equipment", "String", strEquipment, "")
        strParameter += CombineXMLParameterMultiValue("material", "Material", "String", strMaterialExeCO, "") 'Kevin 2012/11/22,修改傳入的物料資訊
        strParameter += CombineXMLParameterMultiValue("materiallot", "MaterialLot", "String", strMaterialLot, "")
        If (bBinNew = True) Then
            For Each drTemp As DataRow In dsWIP.Tables(strSysBin).Rows
                strNewBin += CombineXMLValueTag(
                       CombineXMLValue("binno", CInput(drTemp("BinNo").ToString)) &
                       CombineXMLValue("binqty", CInput(dtBinNew.Rows(0)(drTemp("BinNo").ToString))))

            Next

            strParameter += CombineXMLParameterMultiValue("newbin", "NewBin", "String", strNewBin, "")
        End If
        strParameter += CombineXMLParameterMultiValue("error", "Error", "String", strError, "")
        strParameter += CombineXMLParameter("lotrecord", "LotRecord", "String", CInput(txtLotRecord.Text), "")
        strParameter += CombineXMLParameter("ruleno", "RuleNo", "String", CInput(strRuleNo), "") 'Added by Jialing 2011/02/17
        '20180105 KevinChang 若有選取則加入聯產品資訊
        '2020/6/10, Mantis 0073105: [6.0.5] 產品變更_L_CO_GEN 調整, 有勾起聯產品才傳入聯產品資訊
        If Not IsDBNull(txtUnionProductNo.Text) AndAlso Not String.IsNullOrEmpty(txtUnionProductNo.Text) Then
            strParameter += CombineXMLParameter("fromproductno", "FromProductNo", "String", dsWIP.Tables(tbllotbasis).Rows(0)("ProductNo").ToString, "")
            strParameter += CombineXMLParameter("fromproductversion", "FromProductVersion", "String", dsWIP.Tables(tbllotbasis).Rows(0)("ProductVersion").ToString, "")
            strParameter += CombineXMLParameter("toproductno", "ToProductNo", "String", CInput(txtUnionProductNo.Text), "")
            strParameter += CombineXMLParameter("toproductversion", "ToProductVersion", "String", CInput(txtUnionProductVersion.Text), "")
            strParameter += CombineXMLParameter("toproductunitno", "ToProductUnitNo", "String", CInput(txtUnionProductUnit.Text), "")
        End If

        '2017/11/06 KunYuan：當有勾選『變更結束加工時間』，再傳入CheckOutTime
        If chkUpdCheckOutTime.Checked Then
            strParameter += CombineXMLParameter("checkouttime", "CheckOutTime", "String", dtpcheckouttime.Value.ToString("yyyy/MM/dd HH:mm:ss"), "")
        End If

        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            '2019/06/20 Lena, Mantis: 0058845 [WIP] CI/CO執行時間紀錄
            '新增參數 LogOn = True, 記錄執行時間.
            OutXml = InvokeSrv("wsWIP.Exe_CheckOut", InXml, LogOn:=True)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then '找出Exception訊並顯示出來
                '成功執行完成,避免再按下一次
                btnConfirm.Enabled = False

                '2017/11/06 KunYuan：變更結束加工時間checkbox預設不勾選
                chkUpdCheckOutTime.Checked = False

                '惟全：判斷是否開立異常單
                If XmlDoc.GetElementsByTagName("holdlotno").Count > 0 Then
                    If XmlDoc.GetElementsByTagName("holdlotno").Item(0).SelectNodes("value").Count > 0 Then
                        strHoldLotNo = XmlDoc.DocumentElement.GetElementsByTagName("holdlotno").Item(0).SelectNodes("value").Item(0).InnerText

                        '2021/11/24,Ning, 102031: 【瑶华】qtime卡控不断触发
                        strLinkName = "HOLD"
                    End If
                End If

                If strLinkName <> "HOLD" And strLinkName <> "WAIT" Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-000001", "[%LotNo%]:" & LotNo & " [%Check Out%] [%Successfully%]"), MsgBoxStyle.Information, Me.Text)
                End If

            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                GoTo lblExitProcedure
            End If
            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            GoTo lblExitProcedure
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            GoTo lblExitProcedure
        End Try

        Me.Close()

        '惟全：判斷是否開立異常單
        If strHoldLotNo <> defString Then
            If intERFType = defInteger Then
                intERFType = 0
            End If

            '89904: 6.0.5.12 L_CO_GEN出站觸發Hold 開立異常單未帶出異常說明 2021/03/23
            '開立異常單
            '//CCC 07,0608: 傳入過帳人員
            ' 2016/08/12 YF, WP_BRERFCreate
            'Dim parameters As New Dictionary(Of String, Object)
            'parameters.Add("LotNo", strHoldLotNo)
            'parameters.Add("UserId", UserId)
            'parameters.Add("ERFType", 1)
            'parameters.Add("RuleNo", strExceedTime_Rule)
            'Me.ObjectFileHandler.Execute("WP_BRERFCreate", parameters)
            'Exit Sub
            If strRuleNo <> defString Then
                strRuleNo += "," & strExceedTime_Rule
            Else
                strRuleNo = strExceedTime_Rule
            End If

        End If

        '10.Mail-------------------------------------------------------------------------------------------------------------
        '以下的執行,不管成功失敗,都讓FormClose,代表此BR已完成

        If strMailGroupNo <> "" Then
            Call SendEmailToERFGroup_NoneERF(LotNo, UserId, strMailGroupNo, strMsg,
                dsWIP.Tables(tblLotState).Rows(0)("OPNo"), dsWIP.Tables(tblLotState).Rows(0)("OPName"), dsWIP.Tables(tblLotState).Rows(0)("BRNo"))
        End If

        '11.Transfer Lot-----------------------------------------------------------------------------------------------------
        '以下的執行,不管成功失敗,都讓FormClose,代表此BR已完成
        '若再執行Confirm一次則不正確,同一BR會執行多次
        '2015-12-21, Joe, 加ERFMsg
        '2020/6/11, Ning, 若有變更產品且為新模式, LinkName = PASS則不需TransferLot
        If chkUnionProductNo.Checked = True AndAlso blnPRDChgDetail = True AndAlso strLinkName.ToUpper = "PASS" Then
        Else
            Call BRTransferLot(LotNo, UserId, strLinkName, intERFType, strRuleNo, , strERFMsg)
        End If

        gReturnKeyValue = LotNo


lblExitProcedure:

        Cursor.Current = Cursors.Default
        Exit Sub

    End Sub

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

        Cursor.Current = Cursors.WaitCursor

        '檢查此 BR 是否此站第一次執行，若是第一次執行則以Reverse取消Trigger OP的動作
        Try
            '2019/12/17 OwenLiu, Mantis:0063698, ReverseTriggerOP統一呼叫 WIP_Kit共用函式
            'Call ExeReverseTriggerOP(UserId, LotNo, RevLotSerial, RevLotStamp)

            '2020/3/17,Ning,不啟用Reverse時的ReverseTriggerOP
            '2022/9/19,Ning, 116091: 各BR 在畫面關閉動作執行ReverseTriggerOP，若有執行失敗須把訊息顯示:統一在form_closing時處理
            'Call ExeReverseTriggerOP_NotUseUndo(UserId, LotNo, RevLotSerial, RevLotStamp)

        Catch e1 As Exception
        Finally
            Me.Close()
        End Try

        Cursor.Current = Cursors.Default

    End Sub

    Private Sub btnMultiUser_Click(sender As System.Object, e As System.EventArgs) Handles btnMultiUser.Click

        ' 2016/08/30 YF, 不直接參考改用invoke叫用 
        Dim parameters As New Dictionary(Of String, Object)
        parameters.Add("CallType", 2)
        parameters.Add("UserID", UserId)
        parameters.Add("CheckOutTime", dtpcheckouttime.Value)
        parameters.Add("drLotInfo", dsWIP.Tables(tblLotState).Rows(0))
        '2019/10/18 Grace 調整ObjectID 
        Me.ObjectFileHandler.Execute("WP_OperatorLogIn_Lot", parameters)
        'Me.ObjectFileHandler.Execute("WP_OperatorLogin_Lot", parameters)
        'Dim frmLogin As New frmOperatorLogin_Lot
        'frmLogin.CallType = 2 'CO
        'frmLogin.UserID = UserId
        'frmLogin.CheckOutTime = dtpcheckouttime.Value
        'frmLogin.drLotInfo = dsWIP.Tables(tblLotState).Rows(0)
        'frmLogin.ShowDialog()
        'frmLogin.Dispose()

    End Sub

#End Region

#Region "--- Material ---"

    Private Sub txtMaterialNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMaterialNo.KeyPress

        If e.KeyChar <> Convert.ToChar(13) Then Exit Sub

        If dsWIP.Tables(tblTMaterial) Is Nothing OrElse txtMaterialNo.Text.Trim = "" Then Exit Sub
        txtMaterialNo.Text = txtMaterialNo.Text.ToUpper     '輸入小寫自動轉成大寫
        'Gary Lu:刷完物料編號後準備刷物料批號
        txtMaterialLotNo.Focus()

        'Cursor.Current = Cursors.WaitCursor

        'Dim drSel() As DataRow
        'drSel = dsWIP.Tables(tblTMaterial).Select("MaterialNo='" & txtMaterialNo.Text & "'")
        'If drSel.Length > 0 Then
        '    Dim frmMaterial As frmMaterialQtyInput_Main
        '    frmMaterial = New frmMaterialQtyInput_Main
        '    frmMaterial.drMaterial = drSel(0)
        '    'frmMaterial.LotStateQty = txtCurQty.Text
        '    'If drSel(0)("CheckLotNo") = 1 Then frmMaterial.dtMLot = dtMLot
        '    frmMaterial.dtMLot = dtMLot
        '    'Show Form
        '    frmMaterial.ShowDialog()

        '    'Return Value
        '    'If drSel(0)("CheckLotNo") = 1 Then dtMLot = frmMaterial.dtMLot '將MaterialLot輸入資料取回
        '    dtMLot = frmMaterial.dtMLot '將MaterialLot輸入資料取回
        '    If gReturnKeyValue <> defString Then    '更新數量
        '        drSel(0).BeginEdit()
        '        drSel(0)("UseQty") = gReturnKeyValue
        '        drSel(0).EndEdit()
        '    End If
        '    frmMaterial.Dispose()
        'End If

        'Cursor.Current = Cursors.Default

    End Sub

    Private Sub btnKeyIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeyIn.Click

        If iugMaterial.iMESUltraGrid.ActiveRow Is Nothing Then Exit Sub

        Cursor.Current = Cursors.WaitCursor

        '找出DataSet中在目前游標列的資料列(DataRow)
        Dim strMaterialNo As String = iugMaterial.iMESUltraGrid.ActiveRow.Cells("MaterialNo").Value
        Dim drSel() As DataRow = dsWIP.Tables(tblTMaterial).Select("MaterialNo='" & strMaterialNo & "'")
        If drSel.Length = 0 Then Exit Sub

        ' 2016/08/30 YF, 不直接參考改用invoke叫用 
        Dim drTMaterial As DataRow = drSel(0)
        Dim parameters As New Dictionary(Of String, Object) From {
            {"drMaterial", drTMaterial},
            {"dtMLot", dtMLot}
        }
        Me.ObjectFileHandler.Execute("WP_MaterialQtyInput_Main", parameters)

        dtMLot = parameters("dtMLot")
        For Each drMLot As DataRow In dtMLot.Rows
            If drMLot("UseQty") <= 0 Then
                drMLot("UseQty") = funCalculateUseQty(drTMaterial, drMLot)
            End If
        Next

        funUpdateSumUseQty(drTMaterial)

        'ActiveRow若消失→ActiveRow設定在上一層的UltraGrid上
        If iugMaterial.iMESUltraGrid.ActiveRow Is Nothing Then
            iugMaterial.iMESUltraGrid.ActiveRow = FindRecordPosition(iugMaterial, "MaterialNo", strMaterialNo)
        End If

        'Gary Lu 20131105:使用者改用「輸入」方式選擇要扣那些料批的料後，物料編號和物料批號兩個輸入方塊全清空
        txtMaterialLotNo.Clear()
        txtMaterialNo.Clear()
        txtMaterialNo.Focus()

        Cursor.Current = Cursors.Default

    End Sub

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

        If iugMaterial.iMESUltraGrid.ActiveRow Is Nothing Then Exit Sub

        Cursor.Current = Cursors.WaitCursor
        Dim strMaterialNo As String = iugMaterial.iMESUltraGrid.ActiveRow.Cells("MaterialNo").Value
        '找出DataSet中在目前游標列的資料列(DataRow)
        Dim drSel() As DataRow
        'Gary Lu 20131106:判斷使用者要刪除的是怎樣的資料
        If iugMaterial.iMESUltraGrid.ActiveRow.Band.Key = tblTMaterial Then
            '要刪除的是主料的用料資訊
            drSel = dsWIP.Tables(tblTMaterial).Select("MaterialNo = '" & strMaterialNo & "'")
            If drSel.Length > 0 Then
                dsWIP.Tables(tblTMaterial).Rows.Remove(drSel(0))
                dsWIP.Tables(tblTMaterial).AcceptChanges()
            End If
            'dtMLot關於此主料資訊一併清除
            drSel = dtMLot.Select("MaterialNo = '" & strMaterialNo & "'")
            For i As Integer = 0 To drSel.Length - 1
                dtMLot.Rows.Remove(drSel(i))
            Next

            dtMLot.AcceptChanges()

        ElseIf iugMaterial.iMESUltraGrid.ActiveRow.Band.Key = dtMLot.TableName Then
            Dim strSubstituteMaterialNo As String = iugMaterial.iMESUltraGrid.ActiveRow.Cells("SubstituteMaterialNo").Value

            '要刪除的是使用者所選的一筆要扣料的資訊
            drSel = dtMLot.Select("MaterialNo='" & strMaterialNo &
                                  "' and SubstituteMaterialNo='" & strSubstituteMaterialNo &
                                  "' and MaterialLotNo='" & iugMaterial.iMESUltraGrid.ActiveRow.Cells("MaterialLotNo").Value & "'")
            '紀錄物料編號

            Dim decMaterialUseQty As Decimal = iugMaterial.iMESUltraGrid.ActiveRow.Cells("UseQty").Value
            If drSel.Length > 0 Then
                dtMLot.Rows.Remove(drSel(0))
                dtMLot.AcceptChanges()
            End If
            'TempMaterial中的使用數量必須更新
            drSel = dsWIP.Tables(tblTMaterial).Select("MaterialNo = '" & strMaterialNo & "'")
            If drSel.Length > 0 Then
                drSel(0).BeginEdit()
                drSel(0)("UseQty") -= decMaterialUseQty
                drSel(0).EndEdit()
            End If

            '更新ActiveRow的位置
            drSel = dtMLot.Select("MaterialNo='" & strMaterialNo & "'")
            If drSel.Length > 0 Then
                '還有主料本身或替代料的用料資訊
                iugMaterial.iMESUltraGrid.ActiveRow = FindRecordPosition(iugMaterial, "MaterialNo", strMaterialNo).GetChild(ChildRow.First)
            Else
                '已沒有用料資訊了
                iugMaterial.iMESUltraGrid.ActiveRow = FindRecordPosition(iugMaterial, "MaterialNo", strMaterialNo)
            End If
        End If
        drSel = Nothing

        Cursor.Current = Cursors.Default

    End Sub


#End Region

#Region "--- Error ---"

    Private Sub txtErrorNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtErrorNo.KeyPress

        If e.KeyChar = Convert.ToChar(13) Then
            If txtErrorNo.Text.Trim = "" Then Exit Sub
            txtErrorQty.Focus()
        End If

    End Sub

    Private Sub txtErrorQty_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtErrorQty.KeyPress, txtUnionProductVersion.KeyPress

        If e.KeyChar <> Convert.ToChar(13) Then Exit Sub

        If txtErrorNo.Text.Trim = "" Then Exit Sub
        If txtErrorQty.Text.Trim = "" Then Exit Sub

        Cursor.Current = Cursors.WaitCursor

        If IsNumeric(txtErrorQty.Text) Then
            If txtErrorQty.Text <= 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200017", "[%ErrorQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                txtErrorQty.Focus()
                Exit Sub
            End If
            'If InStr(txtErrorQty.Text, ".", CompareMethod.Text) > 0 Then
            '    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200015", "ErrorQty can't be decimal!!"), MsgBoxStyle.Exclamation, Me.Text)
            '    txtErrorQty.Focus()
            '    Exit Sub
            'End If
        Else
            iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%ErrorQty%]"), MsgBoxStyle.Exclamation, Me.Text)
            txtErrorQty.Focus()
            Exit Sub
        End If

        Dim drSel() As DataRow
        Dim strErrorNo As String
        strErrorNo = txtErrorNo.Text.Trim.ToUpper
        drSel = dsWIP.Tables(tblOPError).Select("ErrorNo='" & strErrorNo & "'")
        If drSel.Length > 0 Then
            drSel(0).BeginEdit()
            drSel(0)("CheckFlag") = True
            drSel(0)("ErrorQty") = txtErrorQty.Text
            drSel(0).EndEdit()

            'Focus在勾選的Row.
            iugError.iMESUltraGrid.Selected.Rows.Clear()
            ugrRow = FindRecordPosition(iugError, "ErrorNo", strErrorNo)
            If Not ugrRow Is Nothing Then
                iugError.iMESUltraGrid.ActiveRow = ugrRow
                iugError.iMESUltraGrid.ActiveRow.Selected = True
            End If

            '加入後清除
            txtErrorNo.Text = ""
            txtErrorQty.Text = ""
            txtErrorNo.Focus()
        Else
            txtErrorNo.Focus()
        End If
        drSel = Nothing
        'Elena 2011/11/8 R1111002 自動計算GoodQty、ScrapQty及DefectQty數量
        If funGetParameter("SysInfo", "CalculateQty") = 1 Then
            Dim drSelError() As DataRow
            Dim decScrapQty As Decimal = 0
            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=0 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decScrapQty = decScrapQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'ScrapQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decScrapQty
            End If
            drSelError = dtKeyIn.Select("AttribNo = 'GoodQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = CDec(txtCurQty.Text) - decScrapQty
            End If

            Dim decDefectQty As Decimal = 0
            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=1 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decDefectQty = decDefectQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'DefectQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decDefectQty
            End If
            drSelError = Nothing
        End If
        Cursor.Current = Cursors.Default

    End Sub


#End Region

#Region "--- Control Enter,KeyPress ---"

    Private Sub txtLotNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLotNo.Enter
        txtLotNo.SelectAll()
    End Sub
    Private Sub txtLotNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLotNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtPriority_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPriority.Enter
        txtPriority.SelectAll()
    End Sub
    Private Sub txtPriority_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPriority.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtAreaNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAreaNo.Enter
        txtAreaNo.SelectAll()
    End Sub
    Private Sub txtAreaNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAreaNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtCurQty_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCurQty.Enter
        txtCurQty.SelectAll()
    End Sub
    Private Sub txtCurQty_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCurQty.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtCurUnitNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCurUnitNo.Enter
        txtCurUnitNo.SelectAll()
    End Sub
    Private Sub txtCurUnitNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCurUnitNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtSysQty_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSysQty.Enter
        txtSysQty.SelectAll()
    End Sub
    Private Sub txtSysQty_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSysQty.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtSysUnitNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSysUnitNo.Enter
        txtSysUnitNo.SelectAll()
    End Sub
    Private Sub txtSysUnitNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSysUnitNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtOPNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOPNo.Enter
        txtOPNo.SelectAll()
    End Sub
    Private Sub txtOPNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtOPNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtOPDescription_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOPDescription.Enter
        txtOPDescription.SelectAll()
    End Sub
    Private Sub txtOPDescription_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtOPDescription.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtCustomerLotNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerLotNo.Enter
        txtCustomerLotNo.SelectAll()
    End Sub
    Private Sub txtCustomerLotNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerLotNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtMONo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMONo.Enter
        txtMONo.SelectAll()
    End Sub
    Private Sub txtMONo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMONo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtEmployeeNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEmployeeNo.Enter
        txtEmployeeNo.SelectAll()
    End Sub
    Private Sub txtEmployeeNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEmployeeNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtShiftNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtShiftNo.Enter
        txtShiftNo.SelectAll()
    End Sub
    Private Sub txtShiftNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtShiftNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtLotRecord_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLotRecord.Enter
        txtLotRecord.SelectAll()
    End Sub

    Private Sub txtProductNo_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtProductNo.Enter
        txtProductNo.SelectAll()
    End Sub
    Private Sub txtProductNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtProductNo.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtMaterialLotNo_Enter(sender As System.Object, e As System.EventArgs) Handles txtMaterialLotNo.Enter
        txtMaterialLotNo.SelectAll()
    End Sub
    Private Sub txtMaterialLotNo_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtMaterialLotNo.KeyPress

        If e.KeyChar <> Convert.ToChar(13) Then
            Exit Sub
        End If

        If txtMaterialLotNo.Text.Trim = "" Then
            Exit Sub
        End If

        ' 2016/10/27 YF, 依作業站用料選項處理用料機制
        Select Case dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString
            Case "0"
                ' 發料點(線邊倉或工單)
                AutoFeedingByPutinPlace(txtMaterialNo.Text, txtMaterialLotNo.Text)
            Case "1"
                ' 設備
                '2019/9/6,Ning,Co時不允許設備上料
                'AutoFeedingByEQP()
            Case "2"
                ' 生產線, 待組裝版再實作
            Case "3"
                ' 工位, 待組裝版再實作
            Case Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-003000", "[%MaterialOption%]：" & dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString & " [%NOT DEFINE%]!"), MsgBoxStyle.Exclamation, Me.Text)
        End Select

    End Sub

#End Region

#Region "--- Ultra Grid ---"

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

        Dim i As Integer

        With e.Layout
            For i = 0 To dsWIP.Tables(tblTAttrib).Columns.Count - 1
                Select Case dsWIP.Tables(tblTAttrib).Columns(i).ColumnName.ToUpper
                    Case "ATTRIBNO"
                        With .Bands(tblTAttrib).Columns("AttribNo")
                            .Header.Caption = "AttribNo"
                            .Width = 70
                            .Header.VisiblePosition = 1
                        End With
                    Case "ATTRIBNAME"
                        With .Bands(tblTAttrib).Columns("AttribName")
                            .Header.Caption = "AttribName"
                            .Width = 95
                            .Header.VisiblePosition = 2
                        End With
                    Case "ATTRIBVALUE"
                        With .Bands(tblTAttrib).Columns("AttribValue")
                            .Header.Caption = "AttribValue"
                            .Width = 80
                            .Header.VisiblePosition = 3
                        End With
                    Case "ATTRIBSOURCE"
                        With .Bands(tblTAttrib).Columns("AttribSource")
                            .Header.Caption = "AttribSource"
                            .Width = 65
                            .Header.VisiblePosition = 4
                            .ValueList = iugAttrib.iMESUltraGrid.DisplayLayout.ValueLists("ASource")
                        End With
                    Case Else
                        With .Bands(tblTAttrib).Columns(dsWIP.Tables(tblTAttrib).Columns(i).ColumnName.ToUpper)
                            .Hidden = True
                        End With
                End Select
            Next

        End With


    End Sub

    Private Sub iugAttrib_iMESUltraGrid_InitializeRow(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles iugAttrib.iMESUltraGrid_InitializeRow

        Dim strAttribValue As String
        strAttribValue = e.Row.Cells("AttribValue").Value.ToString.Trim

        '\\Server\01A.pdf
        If Mid(strAttribValue, 1, 2) = "\\" Then
            e.Row.Cells("AttribValue").Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button
            e.Row.Cells("AttribValue").Appearance.BackColor = System.Drawing.Color.Pink
        End If
        '\\HTTP
        If Mid(strAttribValue.ToUpper, 1, 4) = "HTTP" Then
            e.Row.Cells("AttribValue").Style = ColumnStyle.Button
            e.Row.Cells("AttribValue").Appearance.BackColor = System.Drawing.Color.Pink
        End If
        '\\HTTPS
        If Mid(strAttribValue.ToUpper, 1, 5) = "HTTPS" Then
            e.Row.Cells("AttribValue").Style = ColumnStyle.Button
            e.Row.Cells("AttribValue").Appearance.BackColor = System.Drawing.Color.Pink
        End If

    End Sub

    Private Sub iugAttrib_iMESUltraGrid_ClickCellButton(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles iugAttrib.iMESUltraGrid_ClickCellButton

        Cursor.Current = Cursors.WaitCursor

        Dim strFilePath As String

        strFilePath = e.Cell.Row.Cells("AttribValue").Value.ToString.Trim

        If strFilePath = "" Then Exit Sub

        Try
            Dim objProcess As New Process
            objProcess.Start(strFilePath)

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

        Cursor.Current = Cursors.Default

    End Sub

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

        Dim i As Integer

        With e.Layout
            For i = 0 To dsWIP.Tables(tblTMaterial).Columns.Count - 1
                Select Case dsWIP.Tables(tblTMaterial).Columns(i).ColumnName.ToUpper
                    Case "MATERIALLEVELSHOW"
                        With .Bands(tblTMaterial).Columns("MaterialLevelShow")
                            .Header.Caption = "MaterialLevelShow"
                            .Hidden = False
                            .CalculateAutoResizeWidth(PerformAutoSizeType.VisibleRows, True)
                            .Header.VisiblePosition = 0
                            .ValueList = vlMaterialLevel
                            .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                            .TabStop = False
                        End With
                    Case "MATERIALNO"
                        With .Bands(tblTMaterial).Columns("MaterialNo")
                            .Header.Caption = "MaterialNo"
                            .Width = 110
                            .Header.VisiblePosition = 1
                            .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                            .TabStop = False
                        End With
                    Case "STDQTY"
                        With .Bands(tblTMaterial).Columns("StdQty")
                            .Header.Caption = "StdQty"
                            .Width = 100
                            .Header.VisiblePosition = 2
                            .CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
                            .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                            .Format = "0.########"
                            .TabStop = False
                        End With
                    Case "STDUSEQTY"
                        With .Bands(tblTMaterial).Columns("StdUseQty")
                            .Header.Caption = "StdUseQty"
                            .Width = 80
                            .Header.VisiblePosition = 3
                            .CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
                            .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                            .TabStop = False
                        End With
                    Case "USEQTY"
                        With .Bands(tblTMaterial).Columns("UseQty")
                            .Header.Caption = "UseQty"
                            .Width = 80
                            .Header.VisiblePosition = 4
                            .CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
                            .CellAppearance.BackColor = System.Drawing.Color.White
                            .CellAppearance.ForeColor = System.Drawing.Color.Blue
                        End With
                    Case "UNITNO"
                        With .Bands(tblTMaterial).Columns("UnitNo")
                            .Header.Caption = "UnitNo"
                            .Width = 40
                            .Header.VisiblePosition = 5
                            .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                            .TabStop = False
                        End With
                    Case Else
                        With .Bands(tblTMaterial).Columns(dsWIP.Tables(tblTMaterial).Columns(i).ColumnName.ToUpper)
                            .Hidden = True
                        End With
                End Select
            Next

            If Not dtMLot Is Nothing Then
                For Each dc As DataColumn In dsWIP.Tables(dsWIP.Tables(dtMLot.TableName).TableName).Columns
                    With .Bands(dsWIP.Tables(dtMLot.TableName).TableName).Columns(dc.ColumnName.ToUpper)
                        .Hidden = True
                    End With
                Next

                With .Bands(dsWIP.Tables(dtMLot.TableName).TableName)
                    With .Columns("EquipmentNo")
                        .Width = 110
                        .Header.VisiblePosition = 1
                        .Header.Appearance.BackColor = System.Drawing.Color.Yellow
                        If blnByEQP = True Then
                            .Hidden = False
                        Else
                            .Hidden = True
                        End If
                    End With
                    With .Columns("MaterialNo")
                        .Width = 110
                        .Header.VisiblePosition = 1
                        .Header.Appearance.BackColor = System.Drawing.Color.Yellow
                        .Hidden = True
                    End With
                    With .Columns("SubstituteMaterialNo")
                        .Width = 110
                        .Header.VisiblePosition = 2
                        .Header.Appearance.BackColor = System.Drawing.Color.Yellow
                        .Hidden = False
                    End With
                    With .Columns("MaterialLotNo")
                        .Width = 100
                        .Header.VisiblePosition = 3
                        .Header.Appearance.BackColor = System.Drawing.Color.Yellow
                        .Hidden = False
                    End With
                    With .Columns("Qty")
                        .Width = 100
                        .Header.VisiblePosition = 4
                        .Format = "0.########"
                        .Header.Appearance.BackColor = System.Drawing.Color.Yellow
                        .CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
                        .Hidden = False
                    End With
                    With .Columns("UseQty")
                        .Width = 80
                        .Header.VisiblePosition = 5
                        .Format = "0.########"
                        .Header.Appearance.BackColor = System.Drawing.Color.Yellow
                        .CellAppearance.BackColor = System.Drawing.Color.White
                        .CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
                        .Hidden = False
                    End With
                    .SortedColumns.Add("SubstituteMaterialNo", False, False)
                    .SortedColumns.Add("MaterialLotNo", False, False)
                End With
            End If

            iugMaterial.iMESUltraGrid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.True

        End With

    End Sub

    Private Sub iugMaterial_iMESUltraGrid_InitializeRow(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles iugMaterial.iMESUltraGrid_InitializeRow

        If e.Row.Band.Key = tblTMaterial Then
            'If e.Row.Cells("CheckLotNo").Value = 1 Then '不允許直接編輯

            e.Row.Cells("UseQty").Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
            e.Row.Cells("UseQty").Appearance.BackColor = System.Drawing.Color.Gainsboro
            'End If
        End If


    End Sub

    Private Sub iugMaterial_iMESUltraGrid_BeforeCellUpdate(sender As System.Object, e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles iugMaterial.iMESUltraGrid_BeforeCellUpdate
        If e.Cell.Column.Key.ToUpper = "USEQTY" Then
            If IsNumeric(e.NewValue) Then
                If e.NewValue < 0 Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200017", "[%USEQTY%]"), MsgBoxStyle.Exclamation, Me.Text)
                    e.Cancel = True
                    Exit Sub
                End If
            Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%USEQTY%]"), MsgBoxStyle.Exclamation, Me.Text)
                e.Cancel = True
                Exit Sub
            End If
        End If
    End Sub

    Private Sub iugMaterial_iMESUltraGrid_AfterCellUpdate(sender As System.Object, e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles iugMaterial.iMESUltraGrid_AfterCellUpdate
        If e.Cell.Column.Key.ToUpper <> "USEQTY" Then
            Exit Sub
        End If

        Dim strMaterialNo As String = iugMaterial.iMESUltraGrid.ActiveRow.Cells("MaterialNo").Value
        Dim strMaterialLotNo As String = iugMaterial.iMESUltraGrid.ActiveRow.Cells("MaterialLotNo").Value

        Dim drTMaterial() As DataRow
        drTMaterial = dsWIP.Tables(tblTMaterial).Select("MaterialNo = '" & strMaterialNo & "'")
        If drTMaterial.Length > 0 Then
            If e.Cell.Row.Cells("Qty").Value >= e.Cell.Row.Cells("USEQTY").Value Then
                '更新數量
                funUpdateSumUseQty(drTMaterial(0))
            Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-203083", "[%USEQTY%] > [%MATERIALSTATE%], [%MaterialLotNo%]: " & strMaterialLotNo), MsgBoxStyle.Exclamation, Me.Text)

                e.Cell.Row.Cells("USEQTY").Value = 0
                Exit Sub
            End If
        End If
    End Sub

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

        Dim i As Integer

        With e.Layout
            'Equipment
            For i = 0 To dsWIP.Tables(tblTEquipment).Columns.Count - 1
                Select Case dsWIP.Tables(tblTEquipment).Columns(i).ColumnName.ToUpper
                    Case "EQUIPMENTNO"
                        With .Bands(tblTEquipment).Columns("EquipmentNo")
                            .Header.Caption = "EquipmentNo"
                            .Width = 120
                            .Header.VisiblePosition = 2
                        End With
                    Case "EQUIPMENTTYPE"
                        With .Bands(tblTEquipment).Columns("EquipmentType")
                            .Header.Caption = "EquipmentType"
                            .Width = 100
                            .Header.VisiblePosition = 3
                        End With
                    Case Else
                        With .Bands(tblTEquipment).Columns(dsWIP.Tables(tblTEquipment).Columns(i).ColumnName.ToUpper)
                            .Hidden = True
                        End With
                End Select
            Next

            If Not dsWIP.Tables("Chamber") Is Nothing Then
                For i = 0 To dsWIP.Tables("Chamber").Columns.Count - 1
                    Select Case dsWIP.Tables("Chamber").Columns(i).ColumnName.ToUpper
                        Case "EQUIPMENTNO"
                            With .Bands("Chamber").Columns("EquipmentNo")
                                .Header.Caption = "EquipmentNo"
                                .Width = 150
                                .Header.VisiblePosition = 1
                            End With
                        Case "EQUIPMENTNAME"
                            With .Bands("Chamber").Columns("EquipmentName")
                                .Header.Caption = "Equipment Name"
                                .Width = 150
                                .Header.VisiblePosition = 2
                            End With
                        Case "EQUIPMENTTYPE"
                            With .Bands("Chamber").Columns("EquipmentType")
                                .Header.Caption = "EquipmentType"
                                .Width = 100
                                .Header.VisiblePosition = 3
                            End With
                        Case Else
                            With .Bands("Chamber").Columns(dsWIP.Tables("Chamber").Columns(i).ColumnName.ToUpper)
                                .Hidden = True
                            End With
                    End Select
                Next
            End If

            'Kevin 14/02/18,不顯示模治具數量
            If Not dsWIP.Tables("ContAcc") Is Nothing Then
                With .Bands("ContAccessory").Columns("UseQty")
                    .Hidden = True
                End With

                '[Mantis:0107151]L_CO_GEN，配件（模治具）開始時間格式不正確
                With .Bands("ContAccessory").Columns("StartTime")
                    .Format = "yyyy/MM/dd HH:mm:ss"
                    .Width = 120
                End With

                With .Bands("ContAccessory").Columns("EndTime")
                    .Format = "yyyy/MM/dd HH:mm:ss"
                    .Width = 120
                End With

            End If

        End With


        'UltraGrid
        iugEquipment.iMESUltraGrid.Rows.ExpandAll(True)

    End Sub

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

        With e.Layout
            With .Bands("KeyIn").Columns("AttribNo")
                .Header.Caption = "AttribNo"
                .Width = 90
                .Header.VisiblePosition = 1
                .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                .TabStop = False
            End With
            With .Bands("KeyIn").Columns("AttribName")
                .Header.Caption = "AttribName"
                .Width = 150
                .Header.VisiblePosition = 2
                .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                .TabStop = False
            End With
            With .Bands("KeyIn").Columns("AttribValue")
                .Header.Caption = "AttribValue"
                .Width = 130
                .Header.VisiblePosition = 3
                .CellAppearance.BackColor = System.Drawing.Color.White
            End With
            '2015-12-18, Joe, Add
            With .Bands("KeyIn").Columns("QCItemNo")
                .Header.Caption = "QCItemNo"
                .Width = 100
                .Header.VisiblePosition = 4
                .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                .TabStop = False
            End With
            With .Bands("KeyIn").Columns("AttribSequence")
                .Hidden = True
            End With
            With .Bands("KeyIn").Columns("InputType")
                .Hidden = True
            End With
            With .Bands("KeyIn").Columns("DataType")
                .Hidden = True
            End With
            With .Bands("KeyIn").Columns("ValueType")
                .Hidden = True
            End With
        End With

        'UltraGrid
        iugKeyIn.iMESUltraGrid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.True

    End Sub

    Private Sub iugKeyIn_iMESUltraGrid_InitializeRow(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles iugKeyIn.iMESUltraGrid_InitializeRow
        Dim strAttribValue As String

        Try
            strAttribValue = e.Row.Cells("AttribNo").Value.ToString.Trim

            'InputType=1  清單選擇
            If e.Row.Cells("InputType").Value = 1 Then
                e.Row.Cells("AttribValue").Style = ColumnStyle.Button
                e.Row.Cells("AttribValue").Appearance.BackColor = System.Drawing.Color.Pink
            ElseIf e.Row.Cells("DataType").Value = 3 Then
                e.Row.Cells("AttribValue").Style = ColumnStyle.DateTime
                e.Row.Cells("AttribValue").Editor = editor
                e.Row.Cells("AttribValue").Appearance.BackColor = Color.White
            End If


        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Sub
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Sub
        End Try

    End Sub

    Private Sub iugKeyIn_iMESUltraGrid_ClickCellButton(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles iugKeyIn.iMESUltraGrid_ClickCellButton

        Dim intValueType As Integer

        Cursor.Current = Cursors.WaitCursor

        Try

            intValueType = iugKeyIn.iMESUltraGrid.ActiveRow.Cells("ValueType").Value

            If intValueType = 3 OrElse intValueType = 1 Then   'Reference System Parameter / Assign Valid Value
                If Not IsNothing(dsWIP.Tables(strDefaultValue)) Then
                    dsWIP.Tables.Remove(strDefaultValue)
                End If

                strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
                strParameter = CombineXMLParameter("elementno", "PropertyType", "String", iugKeyIn.iMESUltraGrid.ActiveRow.Cells("AttribNo").Value, "")
                InXml = CombineXMLRequest(strIdentity, strParameter)

                OutXml = InvokeSrv("wsSYS.LoadElementValue", InXml)

                Dim XmlDoc As New XmlDocument
                XmlDoc.LoadXml(OutXml)
                If ChkExecutionSuccess(XmlDoc) Then
                    '//取出Data
                    strDefaultValue = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadelementvalue").Item(0).SelectNodes("name").Item(0).InnerXml
                    '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                    XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadelementvalue").Item(0).SelectNodes("schema").Item(0).InnerXml
                    If XmlSchema <> "" Then
                        '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                        tmpStringReader = New System.IO.StringReader(XmlSchema)
                        dsWIP.ReadXmlSchema(tmpStringReader)
                        tmpStringReader.Close()
                    End If
                    XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadelementvalue").Item(0).SelectNodes("value").Item(0).InnerXml
                    If XmlData <> "" And XmlData <> "fail" Then
                        tmpStringReader = New System.IO.StringReader(XmlData)
                        dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)

                        Dim fSearch As New frmCOMSearch
                        '如果 PropertyNo 的有效性檢查來自 MESParameter，則取出有效值提供選擇
                        fSearch.dvSearch = dsWIP.Tables(strDefaultValue).DefaultView
                        fSearch.strFindColumnName = dsWIP.Tables(strDefaultValue).Columns(0).ColumnName
                        '20221214,13871,右鍵 儲存設計 需要使用Owner(程式碼由程序建立)
                        fSearch.ShowDialog(Me)
                        fSearch.Dispose()

                        If Not drSearch Is Nothing Then
                            If Not IsDBNull(drSearch(0).ToString) Then
                                iugKeyIn.iMESUltraGrid.ActiveRow.Cells("AttribValue").Value = drSearch(0).ToString
                            End If
                        End If
                    End If
                Else
                    ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                    Exit Sub
                End If

            End If

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Sub
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Sub
        End Try

    End Sub

    Private Sub iugError_iMESUltraGrid_AfterCellActivate(sender As Object, e As System.EventArgs) Handles iugError.iMESUltraGrid_AfterCellActivate
        'Elena 2011/11/8 R1111002 自動計算GoodQty、ScrapQty及DefectQty數量
        If funGetParameter("SysInfo", "CalculateQty") = 1 Then
            Dim drSelError() As DataRow
            Dim decScrapQty As Decimal = 0
            Dim decLossQty As Decimal = 0

            drSelError = dtKeyIn.Select("AttribNo = 'LossQty'")
            If drSelError.Length <> 0 Then
                If IsNumeric(drSelError(0)("AttribValue")) Then
                    decLossQty = drSelError(0)("AttribValue")
                End If
            End If

            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=0 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decScrapQty = decScrapQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'ScrapQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decScrapQty
            End If
            drSelError = dtKeyIn.Select("AttribNo = 'GoodQty'")
            Dim blnCalulate As Boolean = True '0111211: [49-1]扫脚_check-out_bin分布调整,若有bin分佈調整, 則不自動計算GoodQty 
            If drSelError.Length <> 0 Then
                If HaveLevel AndAlso iGoodBinStateQty <> 0 Then
                    If Not IsNothing(dtBinNew) AndAlso dtBinNew.Rows.Count > 0 Then
                        blnCalulate = False
                    End If
                End If
                If blnCalulate Then
                    drSelError(0)("AttribValue") = CDec(txtCurQty.Text) - decScrapQty - decLossQty
                End If
            End If

            Dim decDefectQty As Decimal = 0
            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=1 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decDefectQty = decDefectQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'DefectQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decDefectQty
            End If
            drSelError = Nothing
        End If
    End Sub

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

        Dim i As Integer

        With e.Layout
            For i = 0 To dsWIP.Tables(tblOPError).Columns.Count - 1
                With .Bands(tblOPError).Columns(dsWIP.Tables(tblOPError).Columns(i).ColumnName.ToUpper)
                    .Header.VisiblePosition = 99
                    .Hidden = True
                End With
            Next

            With .Bands(tblOPError).Columns("CheckFlag")
                .Header.Caption = "Check"
                .Width = 30
                .Header.VisiblePosition = 1
                .CellAppearance.BackColor = System.Drawing.Color.White
                .Hidden = False
            End With
            With .Bands(tblOPError).Columns("ErrorNo")
                .Header.Caption = "ErrorNo"
                .Width = 80
                .Header.VisiblePosition = 2
                .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                .TabStop = False
                .Hidden = False
            End With
            With .Bands(tblOPError).Columns("ReasonName")
                .Header.Caption = "ReasonName"
                .Width = 100
                .Header.VisiblePosition = 3
                .CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly
                .TabStop = False
                .Hidden = False
            End With
            With .Bands(tblOPError).Columns("ErrorQty")
                .Header.Caption = "ErrorQty"
                .Width = 50
                .Header.VisiblePosition = 4
                .CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
                .CellAppearance.BackColor = System.Drawing.Color.White
                .Hidden = False
            End With
            With .Bands(tblOPError).Columns("ReasonType")
                .ValueList = iugError.iMESUltraGrid.DisplayLayout.ValueLists("AReasonType")
            End With

            'GroupBy
            Dim G1 As Infragistics.Win.UltraWinGrid.UltraGridColumn
            G1 = iugError.iMESUltraGrid.DisplayLayout.Bands(tblOPError).Columns("ReasonType")
            iugError.iMESUltraGrid.DisplayLayout.Bands(tblOPError).SortedColumns.Add(G1, False, True)
            iugError.iMESUltraGrid.Rows.ExpandAll(True)

            '客製化加總欄位
            .Bands(tblOPError).Summaries.Add("ErrorQtySum", Infragistics.Win.UltraWinGrid.SummaryType.Custom,
                calCustomer, .Bands(tblOPError).Columns("ErrorQty"), Infragistics.Win.UltraWinGrid.SummaryPosition.UseSummaryPositionColumn, Nothing)

            .Bands(tblOPError).Summaries("ErrorQtySum").Appearance.TextHAlign = Infragistics.Win.HAlign.Right

            '小數點不會顯示,改為Format(decTotal, "0.####")回傳時先format.
            .Bands(tblOPError).Summaries("ErrorQtySum").DisplayFormat = "Sum={0:####}"
        End With

        iugError.iMESUltraGrid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.True

    End Sub

    Private Sub iugError_iMESUltraGrid_AfterCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles iugError.iMESUltraGrid_AfterCellUpdate

        If e.Cell.Column.Key = "CheckFlag" Then
            If e.Cell.Value = False AndAlso e.Cell.Row.Cells("ErrorQty").Value > 0 Then
                Dim drSel() As DataRow
                drSel = dsWIP.Tables(tblOPError).Select("ErrorNo='" & e.Cell.Row.Cells("ErrorNo").Value & "'")
                If drSel.Length > 0 Then
                    drSel(0).BeginEdit()
                    drSel(0)("ErrorQty") = 0
                    drSel(0).EndEdit()
                End If
                drSel = Nothing
            End If
        End If
        'Elena 2011/11/8 R1111002 自動計算GoodQty、ScrapQty及DefectQty數量
        If funGetParameter("SysInfo", "CalculateQty") = 1 Then
            Dim drSelError() As DataRow
            Dim decScrapQty As Decimal = 0
            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=0 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decScrapQty = decScrapQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'ScrapQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decScrapQty
            End If
            drSelError = dtKeyIn.Select("AttribNo = 'GoodQty'")
            Dim blnCalulate As Boolean = True '0111211: [49-1]扫脚_check-out_bin分布调整,若有bin分佈調整, 則不自動計算GoodQty 
            If drSelError.Length <> 0 Then
                If HaveLevel AndAlso iGoodBinStateQty <> 0 Then
                    If Not IsNothing(dtBinNew) AndAlso dtBinNew.Rows.Count > 0 Then
                        blnCalulate = False
                    End If
                End If
                If blnCalulate Then
                    drSelError(0)("AttribValue") = CDec(txtCurQty.Text) - decScrapQty
                End If
            End If

            Dim decDefectQty As Decimal = 0
            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=1 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decDefectQty = decDefectQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'DefectQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decDefectQty
            End If
            drSelError = Nothing
        End If
    End Sub

    Private Sub iugError_iMESUltraGrid_BeforeCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles iugError.iMESUltraGrid_BeforeCellUpdate

        If e.Cell.Column.Key = "ErrorQty" Then
            If Not IsNumeric(e.NewValue) Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%ErrorQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                e.Cancel = True
                Exit Sub
            End If
            If e.NewValue < 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200016", "[%ErrorQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                e.Cancel = True
                Exit Sub
            End If
            'If InStr(e.NewValue, ".", CompareMethod.Text) > 0 Then
            '    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200015", "ErrorQty can't be decimal!!"), MsgBoxStyle.Exclamation, Me.Text)
            '    e.Cancel = True
            '    Exit Sub
            'End If
        End If

    End Sub

#End Region

#Region "--- Load functions ---"

    Private Function funLoadLotBasis() As String

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("baselotno", "BaseLotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadLotBasis", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '讀取取出資料表之名稱
                tbllotbasis = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadlotbasis").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadlotbasis").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadlotbasis").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

            funLoadLotBasis = "suceess"

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

    End Function

    Private Function funLoadLotState() As Integer

        funLoadLotState = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadLotBasisJoinState", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '讀取取出資料表之名稱
                tblLotState = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadlotbasisjoinstate").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadlotbasisjoinstate").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadlotbasisjoinstate").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadLotState = 0

    End Function

    Private Function funLoadTemp_AttribJoinBasis() As Integer

        funLoadTemp_AttribJoinBasis = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadTemp_AttribJoinBasis", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblTAttrib = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadtemp_attrib").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_attrib").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_attrib").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                Call funAddValueList_Attrib()
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadTemp_AttribJoinBasis = 0


    End Function

    Private Function funLoadTemp_Equipment() As Integer

        funLoadTemp_Equipment = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        'strParameter +=CombineXMLParameter("getmaterial", "GetMaterial", "Boolean", True, "")
        strParameter += CombineXMLParameter("getrecipe", "GetRecipe", "Boolean", True, "")

        strParameter += CombineXMLParameter("getchamber", "GetChamber", "Boolean", True, "")

        If dsWIP.Tables(tblParameter).Rows.Count > 0 Then
            If dsWIP.Tables(tblParameter).Rows(0).Item("ParameterValue") = "1" Then
                strParameter += CombineXMLParameter("chambermanage", "ChamberManage", "Boolean", True, "")
            Else
                strParameter += CombineXMLParameter("chambermanage", "ChamberManage", "Boolean", False, "")
            End If
        Else
            strParameter += CombineXMLParameter("chambermanage", "ChamberManage", "Boolean", False, "")

        End If

        strParameter += CombineXMLParameter("getcontaccessory", "GetContAccessory", "Boolean", True, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadTemp_Equipment", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblTEquipment = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadtemp_equipment").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_equipment").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_equipment").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                If Not dsWIP.Tables("ContAcc") Is Nothing Then
                    If dsWIP.Tables("ContAcc").Rows.Count = 0 Then
                        dsWIP.Relations.Remove("ContAccessory")
                        dsWIP.Tables.Remove("ContAcc")
                    End If
                End If
                If Not dsWIP.Tables("RecipeDetail") Is Nothing Then
                    If dsWIP.Tables("RecipeDetail").Rows.Count = 0 Then
                        dsWIP.Relations.Remove("Recipe")
                        dsWIP.Tables.Remove("RecipeDetail")
                    End If
                End If

                iugEquipment.iMESUltraGrid.DataSource = dsWIP.Tables(tblTEquipment)

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

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadTemp_Equipment = 0


    End Function

    Private Function funLoadTemp_Material() As Integer

        funLoadTemp_Material = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadTemp_Material", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblTMaterial = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadtemp_material").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_material").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_material").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                If dsWIP.Tables(tblTMaterial).Rows.Count > 0 Then
                    '加入標準用量欄位
                    Dim colStdQty As New DataColumn
                    colStdQty.ColumnName = "StdUseQty"
                    colStdQty.DataType = System.Type.GetType("System.Decimal")
                    colStdQty.DefaultValue = 0
                    colStdQty.AllowDBNull = False
                    dsWIP.Tables(tblTMaterial).Columns.Add(colStdQty)
                    '加入實際用量欄位
                    Dim colQty As New DataColumn
                    colQty.ColumnName = "UseQty"
                    colQty.DataType = System.Type.GetType("System.Decimal")
                    colQty.DefaultValue = 0
                    colQty.AllowDBNull = False
                    dsWIP.Tables(tblTMaterial).Columns.Add(colQty)

                    dsWIP.Tables(tblTMaterial).Columns("MaterialLevel").ColumnName = "MaterialLevelShow"

                    '計算標準使用量
                    Dim decCurQty, decStdQty As Decimal
                    Dim i As Integer
                    decCurQty = dsWIP.Tables(tblLotState).Rows(0)("CurQty")
                    For i = 0 To dsWIP.Tables(tblTMaterial).Rows.Count - 1
                        decStdQty = decCurQty * dsWIP.Tables(tblTMaterial).Rows(i)("StdQty") * (1 + dsWIP.Tables(tblTMaterial).Rows(i)("DecreaseRate"))
                        dsWIP.Tables(tblTMaterial).Rows(i)("StdUseQty") = Format(decStdQty, "0.########")
                        dsWIP.Tables(tblTMaterial).Rows(i)("UseQty") = Format(0, "0.########")
                        ' 2016/10/20 YF, 一律自動計算標準使用量
                        'If dsWIP.Tables(tblTMaterial).Rows(i)("CountWay") = 0 Then 'Standard才要預設實際用量.
                        '    dsWIP.Tables(tblTMaterial).Rows(i)("UseQty") = Format(decStdQty, "0.######")
                        'End If
                    Next
                    dsWIP.Tables(tblTMaterial).AcceptChanges()

                    'Create Material Lot Table
                    dtMLot = New DataTable("MaterialLot")
                    dtMLot.Columns.Add("EquipmentNo", System.Type.GetType("System.String"))
                    dtMLot.Columns.Add("MaterialNo", System.Type.GetType("System.String"))
                    dtMLot.Columns.Add("MaterialLotNo", System.Type.GetType("System.String"))
                    dtMLot.Columns.Add("Qty", System.Type.GetType("System.Decimal"))
                    dtMLot.Columns.Add("UseQty", System.Type.GetType("System.Decimal"))
                    dtMLot.Columns.Add("SubstituteMaterialNo", System.Type.GetType("System.String"))    '新增一替代料欄位,2010/03/26,by yumei
                    dtMLot.Columns.Add("SubstituteMaterialLevel", System.Type.GetType("System.Int16"))  '新增一替代料位階欄位,2013/01/08,by Kevin
                    dtMLot.Columns.Add("SubstituteMaterialType", System.Type.GetType("System.String"))  '新增一替代料類型欄位,2013/01/08,by Kevin
                    dtMLot.Columns.Add("SubstituteStdQty", System.Type.GetType("System.Decimal"))       '新增一替代料標準用量欄位,2013/01/08,by Kevin
                    dtMLot.Columns.Add("CheckLotNo", System.Type.GetType("System.Int16"))               '新增一替代料是否檢查批號欄位,2013/01/08,by Kevin
                    dtMLot.Columns.Add("AccDate", System.Type.GetType("System.DateTime"))           '新增回溫時間, 只有設備上料會有值

                    '建立Relation
                    dsWIP.Tables.Add(dtMLot)

                    Dim parentColFI(0) As DataColumn
                    Dim childColFI(0) As DataColumn

                    parentColFI(0) = dsWIP.Tables(tblTMaterial).Columns("MaterialNo")
                    childColFI(0) = dsWIP.Tables(dtMLot.TableName).Columns("MaterialNo")

                    '建立主從關係(RelationName會影響WinForm資料的顯示)
                    Dim tmpRe1 As DataRelation
                    tmpRe1 = New DataRelation("MaterialLot", parentColFI, childColFI, False)
                    dsWIP.Relations.Add(tmpRe1)
                    '获取当前工单的物料清单 新设备上料14278
                    Call funLoadMOMaterialList(dsWIP.Tables(tblLotState).Rows(0)("MONo").ToString, dsWIP.Tables(tblLotState).Rows(0)("OPNo").ToString)
                    ' 2016/10/20 YF, 取得上料資訊
                    GetFeedingData()
                End If

                'Binding
                iugMaterial.iMESUltraGrid.DataSource = dsWIP.Tables(tblTMaterial)

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

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadTemp_Material = 0


    End Function

    Private Function funLoadTemp_MaterialLot() As Integer

        Dim drSel As DataRow()

        funLoadTemp_MaterialLot = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadTemp_MaterialLot", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblTMaterialLot = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadtemp_materiallot").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_materiallot").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadtemp_materiallot").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                dsWIP.Tables(tblTMaterialLot).Columns.Add("MainMaterialNo", System.Type.GetType("System.String"))           'BOM中的主料號
                dsWIP.Tables(tblTMaterialLot).Columns.Add("SubstituteMaterialLevel", System.Type.GetType("System.Int16"))  '新增一替代料位階欄位,2013/01/08,by Kevin
                dsWIP.Tables(tblTMaterialLot).Columns.Add("SubstituteMaterialType", System.Type.GetType("System.String"))  '新增一替代料類型欄位,2013/01/08,by Kevin
                dsWIP.Tables(tblTMaterialLot).Columns.Add("SubstituteStdQty", System.Type.GetType("System.Decimal"))       '新增一替代料標準用量欄位,2013/01/08,by Kevin
                dsWIP.Tables(tblTMaterialLot).Columns.Add("CheckLotNo", System.Type.GetType("System.Int16"))               '新增一替代料是否檢查批號欄位,2013/01/08,by Kevin
                dsWIP.Tables(tblTMaterialLot).Columns.Add("Qty", System.Type.GetType("System.Decimal"))
                dsWIP.Tables(tblTMaterialLot).Columns.Add("MFGDate", System.Type.GetType("System.DateTime"))
                dsWIP.Tables(tblTMaterialLot).Columns.Add("ExpireDate", System.Type.GetType("System.DateTime"))
                dsWIP.Tables(tblTMaterialLot).Columns.Add("InputDate", System.Type.GetType("System.DateTime"))

                For Each drTLot As DataRow In dsWIP.Tables(tblTMaterialLot).Rows
                    drSel = dtAllMTLLot.Select("SubstituteMaterialNo = '" & drTLot("MaterialNo") & "' And MaterialLotNo = '" & drTLot("MaterialLotNo") & "'")
                    If drSel.Length > 0 Then
                        drTLot.BeginEdit()
                        drTLot("MainMaterialNo") = drSel(0)("MaterialNo")
                        drTLot("SubstituteMaterialLevel") = drSel(0)("SubstituteMaterialLevel")
                        drTLot("SubstituteMaterialType") = drSel(0)("SubstituteMaterialType")
                        drTLot("SubstituteStdQty") = drSel(0)("SubstituteStdQty")
                        drTLot("CheckLotNo") = drSel(0)("CheckLotNo")
                        drTLot("Qty") = drSel(0)("Qty")
                        drTLot("MFGDate") = drSel(0)("MFGDate")
                        drTLot("ExpireDate") = drSel(0)("ExpireDate")
                        drTLot("InputDate") = drSel(0)("InputDate")
                        drTLot.EndEdit()
                    Else
                        '已不存在庫存中
                    End If
                Next

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

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadTemp_MaterialLot = 0


    End Function


    Private Function funGetShift() As Integer

        funGetShift = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("userno", "UserNo", "String", UserId, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsUSR.GetShift", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '取出ShiftNo
                If XmlDoc.GetElementsByTagName("shiftno").Item(0).SelectNodes("value").Count > 0 Then
                    txtShiftNo.Text = XmlDoc.DocumentElement.GetElementsByTagName("shiftno").Item(0).SelectNodes("value").Item(0).InnerText
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funGetShift = 0

    End Function

    Private Function funGetOPDescription() As Integer

        funGetOPDescription = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.GetLotOPDescription", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                If XmlDoc.GetElementsByTagName("opdescription").Count > 0 Then
                    If XmlDoc.GetElementsByTagName("opdescription").Item(0).SelectNodes("value").Count > 0 Then
                        txtOPDescription.Text = XmlDoc.DocumentElement.GetElementsByTagName("opdescription").Item(0).SelectNodes("value").Item(0).InnerText
                    End If
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funGetOPDescription = 0

    End Function

    Private Function funLoadOPError() As Integer

        funLoadOPError = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        '將OPNo加上CInput轉換特殊字元,2010/04/08,by yumei
        strParameter = CombineXMLParameter("opno", "OPNo", "String", CInput(dsWIP.Tables(tblLotState).Rows(0)("OPNo").ToString), "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsOP.LoadOPErrorJoinBasis", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblOPError = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadoperrorjoinbasis").Item(0).SelectNodes("name").Item(0).InnerXml
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadoperrorjoinbasis").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadoperrorjoinbasis").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                '將不使用的資料移除
                Dim i As Integer
                For i = dsWIP.Tables(tblOPError).Columns.Count - 1 To 0 Step -1
                    If dsWIP.Tables(tblOPError).Columns(i).ColumnName.ToUpper <> "ERRORNO" AndAlso
                        dsWIP.Tables(tblOPError).Columns(i).ColumnName.ToUpper <> "REASONNAME" AndAlso
                        dsWIP.Tables(tblOPError).Columns(i).ColumnName.ToUpper <> "REASONLEVEL" AndAlso
                        dsWIP.Tables(tblOPError).Columns(i).ColumnName.ToUpper <> "REASONTYPE" Then
                        dsWIP.Tables(tblOPError).Columns.Remove(dsWIP.Tables(tblOPError).Columns(i))
                    End If
                Next

                '加入CheckFlag,ErrorQty欄位.
                Dim colCheck As New DataColumn
                colCheck.ColumnName = "CheckFlag"
                colCheck.DataType = System.Type.GetType("System.Boolean")
                colCheck.DefaultValue = False
                colCheck.AllowDBNull = False
                dsWIP.Tables(tblOPError).Columns.Add(colCheck)

                Dim colQty As New DataColumn
                colQty.ColumnName = "ErrorQty"
                colQty.DataType = System.Type.GetType("System.Decimal")
                colQty.DefaultValue = 0
                colQty.AllowDBNull = False
                dsWIP.Tables(tblOPError).Columns.Add(colQty)

                Call funAddValueList_Error()

                'Binding
                iugError.iMESUltraGrid.DataSource = dsWIP.Tables(tblOPError)

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

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        Finally
        End Try

        funLoadOPError = 0


    End Function

    Private Function funLoadSubstituteMaterial_Main(ByVal strMaterialNo As String,
                                                        ByVal strUnitNo As String) As Integer
        funLoadSubstituteMaterial_Main = -1

        If Not IsNothing(dsWIP.Tables(tblSubstituteMaterial)) Then
            dsWIP.Tables.Remove(tblSubstituteMaterial)
        End If

        Dim XmlDoc As New XmlDocument

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", CInput(LotNo), "")
        strParameter += CombineXMLParameter("materialno", "MaterialNo", "String", CInput(strMaterialNo), "")
        strParameter += CombineXMLParameter("unitno", "UnitNo", "String", CInput(strUnitNo), "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.LoadSubstituteMaterial_Main", InXml)

            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblSubstituteMaterial = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadsubstitutematerial_main").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadsubstitutematerial_main").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadsubstitutematerial_main").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadSubstituteMaterial_Main = 0
    End Function

    '2019/01/19 Eric
    Private Sub funLoadParameter(ByVal ParameterNo As String)

        If Not dsWIP.Tables(tblParameter) Is Nothing Then
            dsWIP.Tables.Remove(tblParameter)
        End If

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

        Try
            OutXml = InvokeSrv("wsSYS.LoadParameter", InXml)

            Dim XmlDoc As New XmlDocument   '//處理Xml字串之物件
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblParameter = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadparameter").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadparameter").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadparameter").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                If dsWIP.Tables(tblParameter).Rows.Count > 0 Then
                    strEnableSWR_CICO = dsWIP.Tables(tblParameter).Rows(0)("ParameterValue").ToString
                Else
                    strEnableSWR_CICO = "0"
                End If

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

        Catch ex As Exception
            'MsgBox("Unexpected Error. Load OP Error define relative data Failed!! , " & e1.Message)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally
        End Try

    End Sub


    '2019/10/17 Grace 查詢作業站資料
    Private Sub funLoadOPBasis(ByVal OPNo As String)

        If Not IsNothing(dsTemp.Tables(tblOPBasis)) Then
            dsTemp.Tables.Remove(tblOPBasis)
        End If

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

        Dim XmlDoc As New XmlDocument

        Try
            ' 2016 YF, Using wsOP As New wsOP.wsOP
            ' 2016 YF, wsOP.Url = LocalizeWebService(wsOP.Url.ToString)
            ' 2016 YF, wsOP.EnableDecompression = True
            ' 2016 YF, OutXml = wsOP.LoadOPBasis(InXml)
            OutXml = InvokeSrv("wsOP.LoadOPBasis", InXml)

            ' 2016 YF, End Using

            '利用XmlDoc物件處理ReturnValue 
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '//取出 Tablename
                tblOPBasis = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadopbasis").Item(0).SelectNodes("name").Item(0).InnerXml
                '//取出 Table Schma
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadopbasis").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsTemp.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '//取出Attrib Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadopbasis").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsTemp.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Sub
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Sub
        End Try
    End Sub
#End Region

#Region "--- Others ---"

    Private Function funInitialize()

        iugAttrib.iMESUltraGrid.Text = "Attrib"
        iugAttrib.iMESUltraGrid.DisplayLayout.GroupByBox.Hidden = True
        iugAttrib.iMESUltraGrid.DisplayLayout.MaxColScrollRegions = 1
        iugAttrib.iMESUltraGrid.DisplayLayout.MaxRowScrollRegions = 1
        iugAttrib.iMESUltraGrid.ContextMenuStrip.Items.Clear()
        iugAttrib.iMESUltraGrid.DisplayLayout.Override.CellAppearance.BackColor = Drawing.Color.Gainsboro

        iugEquipment.iMESUltraGrid.Text = "Equipment"
        iugEquipment.iMESUltraGrid.DisplayLayout.GroupByBox.Hidden = True
        iugEquipment.iMESUltraGrid.DisplayLayout.MaxColScrollRegions = 1
        iugEquipment.iMESUltraGrid.DisplayLayout.MaxRowScrollRegions = 1
        iugEquipment.iMESUltraGrid.ContextMenuStrip.Items.Clear()
        iugEquipment.iMESUltraGrid.DisplayLayout.Override.CellAppearance.BackColor = Drawing.Color.Gainsboro

        iugStuInfo.iMESUltraGrid.Text = "StuInfo"

        iugMaterial.iMESUltraGrid.DisplayLayout.GroupByBox.Hidden = True
        iugMaterial.iMESUltraGrid.DisplayLayout.MaxColScrollRegions = 1
        iugMaterial.iMESUltraGrid.DisplayLayout.MaxRowScrollRegions = 1
        iugMaterial.iMESUltraGrid.ContextMenuStrip.Items.Clear()
        iugMaterial.iMESUltraGrid.DisplayLayout.Override.CellAppearance.BackColor = Drawing.Color.Gainsboro
        iugMaterial.iMESUltraGrid.UpdateMode = Infragistics.Win.UltraWinGrid.UpdateMode.OnCellChangeOrLostFocus
        '只有子階有資料時,才有+號.
        iugMaterial.iMESUltraGrid.DisplayLayout.Override.ExpansionIndicator = ShowExpansionIndicator.CheckOnDisplay
        '當子階有資料時,+號自動展開.
        iugMaterial.iMESUltraGrid.Rows.ExpandAll(True)

        iugKeyIn.iMESUltraGrid.Text = "Key In"
        iugKeyIn.iMESUltraGrid.DisplayLayout.GroupByBox.Hidden = True
        iugKeyIn.iMESUltraGrid.DisplayLayout.MaxColScrollRegions = 1
        iugKeyIn.iMESUltraGrid.DisplayLayout.MaxRowScrollRegions = 1
        iugKeyIn.iMESUltraGrid.ContextMenuStrip.Items.Clear()
        iugKeyIn.iMESUltraGrid.DisplayLayout.Override.CellAppearance.BackColor = Drawing.Color.Gainsboro
        iugKeyIn.iMESUltraGrid.UpdateMode = Infragistics.Win.UltraWinGrid.UpdateMode.OnCellChangeOrLostFocus

        iugError.iMESUltraGrid.DisplayLayout.GroupByBox.Hidden = True
        iugError.iMESUltraGrid.DisplayLayout.MaxColScrollRegions = 1
        iugError.iMESUltraGrid.DisplayLayout.MaxRowScrollRegions = 1
        iugError.iMESUltraGrid.ContextMenuStrip.Items.Clear()
        iugError.iMESUltraGrid.DisplayLayout.Override.CellAppearance.BackColor = Drawing.Color.Gainsboro
        iugError.iMESUltraGrid.UpdateMode = Infragistics.Win.UltraWinGrid.UpdateMode.OnCellChangeOrLostFocus

        SBar1.Panels(0).Text = "UserNo:" & UserId
        SBar1.Panels(3).Text = Format(Now, "yyyy/MM/dd H:mm:ss")

        txtPriority.Appearance.TextHAlign = Infragistics.Win.HAlign.Right
        txtCurQty.Appearance.TextHAlign = Infragistics.Win.HAlign.Right
        txtSysQty.Appearance.TextHAlign = Infragistics.Win.HAlign.Right

        'CHECKLXL
        iugStuInfo.iMESUltraGrid.DisplayLayout.GroupByBox.Hidden = True

        btnConfirm.Enabled = True
        'btnMultiUser.Enabled = True

        ' 2016/12/26 YF, 依系統參數是否啟動多人加工來決定是否顯示"作業人員"按鈕
        Me.btnOperator.Visible = Val(funGetParameter("SysInfo", "MultiOperator"))

        '2019/10/17 Grace 依系統參數是否啟動多人加工, 且多人加工模式為生產批, 來決定是否顯示"多人加工"按鈕
        btnMultiUser.Visible = False
        btnMultiUser.Enabled = False

        If Val(funGetParameter("SysInfo", "MultiOperator")) Then
            Call funLoadOPBasis(txtOPNo.Text)
            If Not IsNothing(dsTemp.Tables(tblOPBasis)) Then
                If dsTemp.Tables(tblOPBasis).Rows.Count > 0 Then
                    If dsTemp.Tables(tblOPBasis).Rows(0)("MultiOperatorMode").ToString = "5" Then
                        btnMultiUser.Visible = True
                        btnMultiUser.Enabled = True
                    End If
                End If
            End If
        End If

    End Function

    Private Function funLotInfo_Show()

        RevLotSerial = dsWIP.Tables(tblLotState).Rows(0)("LotSerial")
        RevLotStamp = dsWIP.Tables(tblLotState).Rows(0)("LotStamp")

        txtCurQty.Text = Format(dsWIP.Tables(tblLotState).Rows(0)("CurQty"), "0.####")
        txtCurUnitNo.Text = dsWIP.Tables(tblLotState).Rows(0)("CurUnitNo").ToString
        txtSysQty.Text = Format(dsWIP.Tables(tblLotState).Rows(0)("SysQty"), "0.####")
        txtSysUnitNo.Text = dsWIP.Tables(tblLotState).Rows(0)("SysUnitNo").ToString
        txtOPNo.Text = dsWIP.Tables(tblLotState).Rows(0)("OPNo").ToString
        txtOPName.Text = dsWIP.Tables(tblLotState).Rows(0)("OPName").ToString
        txtAreaNo.Text = dsWIP.Tables(tblLotState).Rows(0)("AreaNo").ToString
        txtProductNo.Text = dsWIP.Tables(tblLotState).Rows(0)("ProductNo").ToString
        PhaseNo = dsWIP.Tables(tblLotState).Rows(0)("PhaseNo")

        txtPriority.Text = dsWIP.Tables(tblLotState).Rows(0)("Priority")
        If dsWIP.Tables(tblLotState).Rows(0)("Priority") = 1 Then
            txtPriority.BackColor = System.Drawing.Color.Red
        ElseIf dsWIP.Tables(tblLotState).Rows(0)("Priority") = 2 Then
            txtPriority.BackColor = System.Drawing.Color.Yellow
        ElseIf dsWIP.Tables(tblLotState).Rows(0)("Priority") = 3 Then
            txtPriority.BackColor = System.Drawing.Color.LimeGreen
        End If
        txtMONo.Text = dsWIP.Tables(tblLotState).Rows(0)("MONo").ToString
        txtCustomerLotNo.Text = dsWIP.Tables(tblLotState).Rows(0)("CustomerLotNo").ToString

    End Function

    Private Sub funAddValueList_Attrib()

        iugAttrib.iMESUltraGrid.DisplayLayout.ValueLists.Add("ASource")
        With iugAttrib.iMESUltraGrid.DisplayLayout.ValueLists("ASource").ValueListItems
            .Clear()
            .Add(0, "KeyIn")
            .Add(1, "Calculate")
            .Add(2, "System")
            .Add(3, "Setup")
        End With

    End Sub

    Private Sub gbxError_Enter(sender As Object, e As EventArgs) Handles gbxError.Enter

    End Sub

    Private Sub funAddValueList_Error()

        iugError.iMESUltraGrid.DisplayLayout.ValueLists.Add("AReasonType")
        With iugError.iMESUltraGrid.DisplayLayout.ValueLists("AReasonType").ValueListItems
            .Clear()
            .Add(0, "Scrap")
            .Add(1, "Defect")
        End With


    End Sub

    Private Function funGetSampleData()

        Cursor.Current = Cursors.WaitCursor

        '轉換抽樣參數
        Dim strAQLType, strAQL, strQCLevel, strTemp As String

        If dsWIP.Tables(tblTAttrib) Is Nothing Then Exit Function

        Dim drSel() As DataRow
        '若已轉換,不再轉
        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'SampleQty'")
        If drSel.Length > 0 Then
            If Not IsDBNull(drSel(0)("AttribValue")) Then
                If drSel(0)("AttribValue") <> "" Then
                    Exit Function
                End If
            End If
        End If

        'AQLType
        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'AQLType'")
        If drSel.Length > 0 Then
            strAQLType = drSel(0)("AttribValue")
        Else
            strAQLType = defString
        End If
        'AQL
        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'AQL'")
        If drSel.Length > 0 Then
            strAQL = drSel(0)("AttribValue")
        Else
            strAQL = defString
        End If
        'QCLevel
        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'QCLevel'")
        If drSel.Length > 0 Then
            strQCLevel = drSel(0)("AttribValue")
        Else
            strQCLevel = defString
        End If

        drSel = Nothing

        If strAQLType = defString Or strAQL = defString Or strQCLevel = defString Then Exit Function

        '取出抽樣數
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("aqltype", "AQLType", "String", strAQLType, "")
        strParameter += CombineXMLParameter("qty", "QTY", "Decimal", dsWIP.Tables(tblLotState).Rows(0)("CurQty"), "")
        strParameter += CombineXMLParameter("qclevel", "QCLevel", "String", strQCLevel, "")
        strParameter += CombineXMLParameter("aql", "AQL", "String", strAQL, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)
        Try
            OutXml = InvokeSrv("wsQC.GetAQLQty", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                'SampleQty
                If XmlDoc.GetElementsByTagName("sampleqty").Item(0).SelectNodes("value").Count > 0 Then
                    strTemp = XmlDoc.DocumentElement.GetElementsByTagName("sampleqty").Item(0).SelectNodes("value").Item(0).InnerText
                    If IsNumeric(strTemp) Then
                        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'SampleQty'")
                        If drSel.Length > 0 Then
                            drSel(0).BeginEdit()
                            drSel(0)("AttribValue") = strTemp
                            drSel(0).EndEdit()
                        End If
                    Else
                        iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%SampleQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                        Exit Function
                    End If
                End If
                'AcceptQty
                If XmlDoc.GetElementsByTagName("acceptqty").Item(0).SelectNodes("value").Count > 0 Then
                    strTemp = XmlDoc.DocumentElement.GetElementsByTagName("acceptqty").Item(0).SelectNodes("value").Item(0).InnerText
                    If IsNumeric(strTemp) Then
                        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'AcceptQty'")
                        If drSel.Length > 0 Then
                            drSel(0).BeginEdit()
                            drSel(0)("AttribValue") = strTemp
                            drSel(0).EndEdit()
                        End If
                    Else
                        iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%AcceptQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                        Exit Function
                    End If
                End If
                'RejectQty
                If XmlDoc.GetElementsByTagName("rejectqty").Item(0).SelectNodes("value").Count > 0 Then
                    strTemp = XmlDoc.DocumentElement.GetElementsByTagName("rejectqty").Item(0).SelectNodes("value").Item(0).InnerText
                    If IsNumeric(strTemp) Then
                        drSel = dsWIP.Tables(tblTAttrib).Select("AttribNo = 'RejectQty'")
                        If drSel.Length > 0 Then
                            drSel(0).BeginEdit()
                            drSel(0)("AttribValue") = strTemp
                            drSel(0).EndEdit()
                        End If
                    Else
                        iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-200011", "[%RejectQty%]"), MsgBoxStyle.Exclamation, Me.Text)
                        Exit Function
                    End If
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing


        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        Cursor.Current = Cursors.Default


    End Function

    Private Function funLoadSYSParameter() As Integer

        funLoadSYSParameter = -1

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

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

        Try
            Dim XmlDoc As New XmlDocument
            OutXml = InvokeSrv("wsSYS.LoadParameter", InXml)

            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblSYSParameter = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadparameter").Item(0).SelectNodes("name").Item(0).InnerXml
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadparameter").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadparameter").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If
        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadSYSParameter = 0

    End Function

    Private Sub funLoadProduct(Optional UnionProductNo As String = defString, Optional blnIssueState As Boolean = True)

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

        '組InXml的字串
        strParameter = ""
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        If blnIssueState Then
            strParameter = CombineXMLParameter("issuestate", "IssueState", "Integer", 2, "")
        End If
        If UnionProductNo <> defString Then
            strParameter = CombineXMLParameter("productno", "ProductNo", "String", UnionProductNo, "")
        End If
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            ' 2016 YF, OutXml = wsPRD.LoadProduct(InXml)
            If blnIssueState = False Then
                OutXml = InvokeSrv("wsPRD.LoadCusProduct", InXml)
            Else
                OutXml = InvokeSrv("wsPRD.LoadProduct", InXml)
            End If

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblProductBasis = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadproduct").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadproduct").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadproduct").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If
        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            'MsgBox("Unexpected Error. Load System Parameter failed," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub

    Private Sub funLoadOEMOBasis()

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

        '組InXml的字串
        strParameter = ""
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("issuestate", "IssueState", "Integer", 2, "")
        strParameter = CombineXMLParameter("mono", "MONO", "String", CInput(txtMONo.Text), "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            ' 2016 YF, OutXml = wsPRD.LoadProduct(InXml)      
            OutXml = InvokeSrv("wsOE.LoadMOBasis", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblOEMOBasis = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadmobasis").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadmobasis").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadmobasis").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If
        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            'MsgBox("Unexpected Error. Load System Parameter failed," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub
    Private Sub btnBinAssign_Click(sender As Object, e As EventArgs) Handles btnBinStateAdjust.Click

        Dim fBinStateAdjust As New frmBinStateAdjust
        fBinStateAdjust.LotNo = LotNo
        fBinStateAdjust.dvSysBin = dvSysBin
        fBinStateAdjust.dtGoodBin = dsWIP.Tables(strBinState)
        fBinStateAdjust.dtBinNew = dtBinNew
        fBinStateAdjust.ShowDialog(Me)
        fBinStateAdjust.Dispose()
        If gReturnKeyValue <> "" Then
            If dtBinNew.Rows.Count > 0 Then
                Dim NewBinQty_Sun As Integer = 0
                For Each drTemp As DataRow In dsWIP.Tables(strSysBin).Rows
                    NewBinQty_Sun += CInt(dtBinNew.Rows(0)(drTemp("BinNo").ToString))
                Next
                Dim drSel As DataRow()
                drSel = dtKeyIn.Select("AttribNo = 'GoodQty'")
                If drSel.Length > 0 Then
                    drSel(0)("AttribValue") = NewBinQty_Sun
                    dtKeyIn.AcceptChanges()
                End If
            End If
        End If
    End Sub
    Private Function funCombineTTInXml(ByVal FromProductNo As String)

        Dim code As String = String.Empty
        Dim sqlcode As String = String.Empty
        Dim description As String = String.Empty
        Dim strAccess As String = String.Empty
        Dim strParameter As String = String.Empty
        Dim strMaster As String = String.Empty
        Dim strDetail As String = String.Empty

        Dim strTempField As String = String.Empty
        Dim strTempRecord As String = String.Empty
        Dim XmlDoc As New XmlDocument()
        Dim dtUnionProduct As DataTable
        Dim arriveTime As DateTime = Now

        '---- InXml -----
        '<Access>
        '2011/12/05 Aaron, 增加系統變數TPERPUseMESUserNo，設定是否使用MES帳號或是tiptop內建帳號進行單據拋送

        Try
            If funGetParameter("SysInfo", "TPERPUseMESUserNo") = 1 Then
                strAccess = cbXMLAccess_TP(gUserNo)
            Else
                strAccess = cbXMLAccess_TP()
            End If

            '<Master>
            strTempField = cbXMLField_TP("condition", "ima01 LIKE '" & FromProductNo & "%'")
            'strTempField += cbXMLField_TP("vdate", Format(dsWIP.Tables(tbllotbasis).Rows(0)("CreateDate"), "yyyy/MM/dd"))
            strTempField += cbXMLField_TP("vdate", "")
            strTempRecord = cbXMLRecord_TP(strTempField)

            '<Parameter>
            strTempRecord = cbXMLRecord_TP(strTempField)
            strParameter = cbXMLParameter_TP(strTempRecord)

            InXml = cbXMLRequest_TP(strAccess, strParameter, strMaster, strDetail)

            '----- Call ERP Web Service -----
            Using ws As New COM_ERP.wsERP_TT.TIPTOPServiceGateWay
                ws.Url = gERPWSURL
                OutXml = ws.GetJointProductData(InXml)
            End Using

            XmlDoc.LoadXml(OutXml)

            '----- 取得ERP執行結果 code, sqlcode, description -----
            chkExecutionStatus_TP(XmlDoc, code, sqlcode, description)

            If code <> "0" Then
                If description <> String.Empty Then
                    'MsgBox(description, , "ERP Return Message")
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Return Message%]" & vbCrLf & description), MsgBoxStyle.Exclamation, Me.Text)
                Else
                    'MsgBox("ERP Fail !")
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Fail%]"), MsgBoxStyle.Exclamation, Me.Text)

                End If
                Exit Function
            End If

            '取得ERP回傳之聯產品資訊
            dtUnionProduct = getResponseContentDetail_TP(XmlDoc)

            '開窗給使用者選擇
            Cursor.Current = Cursors.WaitCursor

            If dtUnionProduct.DefaultView.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP DID NOT RETURN THE JOINT PRODUCT INFORMATION%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            End If

            Dim fSearch As New frmCOMSearch
            fSearch.dvSearch = dtUnionProduct.DefaultView
            fSearch.strFindColumnName = "UnionProductNo"
            '20221214,13871,右鍵 儲存設計 需要使用Owner(程式碼由程序建立)
            fSearch.ShowDialog(Me)
            fSearch.Dispose()

            If drSearch Is Nothing Then Exit Function

            '檢查聯產品資料是否存在系統中以及是否有版本資訊
            funLoadProduct(drSearch("UnionProductNo").ToString.ToUpper, False)

            If dsWIP.Tables(tblProductBasis).Rows.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & ""), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("IssueState") <> 2 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%EDATA%][%Unfrozen%] "), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString <> dsWIP.Tables(tbllotbasis).Rows(0)("ProductVersion").ToString Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%NOTHINGSTATE%][%CURVERSION%][%PRODUCTINFO%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            Else
                txtUnionProductNo.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductNo").ToString
                txtUnionProductVersion.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString
                txtUnionProductUnit.Text = dsWIP.Tables(tblProductBasis).Rows(0)("UnitNo").ToString

                '選取聯產品資訊時, 需自動勾起聯產品checkBox
                chkUnionProductNo.Checked = True
            End If

            Cursor.Current = Cursors.Default

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally

            '紀錄TransactionLog
            addTransactionLog_ErrorCode(InXml, OutXml, arriveTime.ToString("yyyyMMddHHmmssss"), "WIP", "GetJointProductData", My.Computer.Name, gUserNo, arriveTime.ToString("yyyy/MM/dd HH:mm:ss"), code, "", "CreateStockInData", LogClass:="WIP")
        End Try

    End Function
    Private Function funCombineTTICDInXml(ByVal FromProductNo As String)

        Dim code As String = String.Empty
        Dim sqlcode As String = String.Empty
        Dim description As String = String.Empty
        Dim strAccess As String = String.Empty
        Dim strParameter As String = String.Empty
        Dim strMaster As String = String.Empty
        Dim strDetail As String = String.Empty

        Dim strTempField As String = String.Empty
        Dim strTempRecord As String = String.Empty
        Dim XmlDoc As New XmlDocument()
        Dim dtUnionProduct As DataTable
        Dim arriveTime As DateTime = Now

        '---- InXml -----
        '<Access>
        '2011/12/05 Aaron, 增加系統變數TPERPUseMESUserNo，設定是否使用MES帳號或是tiptopicd內建帳號進行單據拋送

        Try
            If funGetParameter("SysInfo", "TPERPUseMESUserNo") = 1 Then
                strAccess = cbXMLAccess_TTICD(gUserNo)
            Else
                strAccess = cbXMLAccess_TTICD()
            End If

            '<Master>
            strTempField = cbXMLField_TTICD("condition", "ima01 LIKE '" & FromProductNo & "%'")
            'strTempField += cbXMLField_TTICD("vdate", Format(dsWIP.Tables(tbllotbasis).Rows(0)("CreateDate"), "yyyy/MM/dd"))
            strTempField += cbXMLField_TTICD("vdate", "")
            strTempRecord = cbXMLRecord_TTICD(strTempField)

            '<Parameter>
            strTempRecord = cbXMLRecord_TTICD(strTempField)
            strParameter = cbXMLParameter_TTICD(strTempRecord)

            InXml = cbXMLRequest_TTICD(strAccess, strParameter, strMaster, strDetail)

            '----- Call ERP Web Service -----
            Using ws As New COM_ERP.wsERP_TT.TIPTOPServiceGateWay
                ws.Url = gERPWSURL
                OutXml = ws.GetJointProductData(InXml)
            End Using

            XmlDoc.LoadXml(OutXml)

            '----- 取得ERP執行結果 code, sqlcode, description -----
            chkExecutionStatus_TTICD(XmlDoc, code, sqlcode, description)

            If code <> "0" Then
                If description <> String.Empty Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Return Message%]" & vbCrLf & description), MsgBoxStyle.Exclamation, Me.Text)
                Else
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Fail%]"), MsgBoxStyle.Exclamation, Me.Text)
                End If
                Exit Function
            End If

            '取得ERP回傳之聯產品資訊
            dtUnionProduct = getResponseContentDetail_TTICD(XmlDoc)

            '開窗給使用者選擇
            Cursor.Current = Cursors.WaitCursor

            If dtUnionProduct.DefaultView.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP DID NOT RETURN THE JOINT PRODUCT INFORMATION%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            End If

            Dim fSearch As New frmCOMSearch
            fSearch.dvSearch = dtUnionProduct.DefaultView
            fSearch.strFindColumnName = "UnionProductNo"
            '20221214,13871,右鍵 儲存設計 需要使用Owner(程式碼由程序建立)
            fSearch.ShowDialog(Me)
            fSearch.Dispose()

            If drSearch Is Nothing Then Exit Function

            '檢查聯產品資料是否存在系統中以及是否有版本資訊
            funLoadProduct(drSearch("UnionProductNo").ToString.ToUpper, False)

            If dsWIP.Tables(tblProductBasis).Rows.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & ""), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("IssueState") <> 2 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%EDATA%][%Unfrozen%] "), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString <> dsWIP.Tables(tbllotbasis).Rows(0)("ProductVersion").ToString Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%NOTHINGSTATE%][%CURVERSION%][%PRODUCTINFO%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            Else
                txtUnionProductNo.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductNo").ToString
                txtUnionProductVersion.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString
                txtUnionProductUnit.Text = dsWIP.Tables(tblProductBasis).Rows(0)("UnitNo").ToString

                '選取聯產品資訊時, 需自動勾起聯產品checkBox
                chkUnionProductNo.Checked = True
            End If

            Cursor.Current = Cursors.Default

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally

            '紀錄TransactionLog
            addTransactionLog_ErrorCode(InXml, OutXml, arriveTime.ToString("yyyyMMddHHmmssss"), "WIP", "GetJointProductData", My.Computer.Name, gUserNo, arriveTime.ToString("yyyy/MM/dd HH:mm:ss"), code, "", "CreateStockInData", LogClass:="WIP")
        End Try

    End Function
    Structure MethodNames
        ''' <summary>檢查物料數量</summary>
        Const funCheckMTLQuantity = "funCheckMTLQuantity"
        ''' <summary>膠類時效卡控</summary>
        Const funCheckMTLGumDefrostHour = "funCheckMTLGumDefrostHour"
    End Structure
    Private Function funCheckMTLForBR(ByVal dtMaterialLot As DataTable,
                                           ByRef strLinkName As String, ByRef intERFType As Int16, ByRef strRuleNo As String) As Boolean

        funOrganizeDtMaterialLot(LotNo, dtMaterialLot)
        dtMaterialLot.DefaultView.RowFilter = "Qty>0"
        dtMaterialLot = dtMaterialLot.DefaultView.ToTable()
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", CInput(LotNo), "")
        strParameter &= CombineXMLParameter("checkin", "CheckIn", "Boolean", CInput(False), "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP_Material.CheckMTLForBR", InXml, dtMaterialLot.Copy)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If Not ChkExecutionSuccess(XmlDoc) Then
                '找出Exception訊並顯示出來
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Return False
            End If

            Dim xmlList As XmlNodeList = XmlDoc.GetElementsByTagName("message")
            If xmlList.Count > 0 Then
                xmlList = xmlList(0).SelectNodes("note")
                If xmlList.Count > 0 Then
                    For Each xmlNode As XmlNode In xmlList
                        If funProcessMessages(xmlNode, strLinkName, intERFType, strRuleNo) = False Then Return False
                    Next
                End If
            End If

            Return True

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Return False
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Return False
        End Try

    End Function
    Private Function funProcessMessages(ByVal xmlNode As XmlNode,
                                        ByRef strLinkName As String, ByRef intERFType As Int16, ByRef strRuleNo As String) As Boolean

        Dim MCode, MType, MMsg As String
        MCode = xmlNode.SelectNodes("mcode").Item(0).InnerText
        MType = xmlNode.SelectNodes("mtype").Item(0).InnerText
        MMsg = xmlNode.SelectNodes("mmsg").Item(0).InnerText

        Dim methodName As String = ""
        If MMsg.Contains("{") AndAlso MMsg.Contains("}") Then
            Dim intStart As Int16 = MMsg.IndexOf("{")
            Dim intEnd As Int16 = MMsg.IndexOf("}")
            methodName = MMsg.Substring(intStart + 1, intEnd - intStart - 1)
            MMsg = MMsg.Substring(intEnd + 1, MMsg.Length - intEnd - 1)
        End If

        Select Case methodName
            Case MethodNames.funCheckMTLQuantity
                If ExceptionManager.iMESMsgBoxShowDialog(
                ChgTranslateName_Msg("0000-100601", MMsg), MsgBoxStyle.YesNo + MsgBoxStyle.Question) = MsgBoxResult.No Then
                    Return False
                End If

            Case MethodNames.funCheckMTLGumDefrostHour
                strLinkName = "HOLD"
                intERFType = 0      'BR Hold
                MMsg = ChgTranslateErrorMsg(MMsg)
                MMsg = MMsg.TrimStart(New Char() {vbCr, vbLf})
                If strRuleNo = defString Then
                    strRuleNo = MMsg
                Else
                    strRuleNo &= (vbCrLf & MMsg)
                End If

            Case Else
                ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg(MCode, MMsg), MsgBoxStyle.Exclamation, Me.Text)
                Return False
        End Select

        Return True

    End Function
    Sub funOrganizeDtMaterialLot(ByVal LotNo As String, ByVal dtMaterialLot As DataTable)

        For i = dtMaterialLot.Columns.Count - 1 To 0 Step -1
            Dim dc As DataColumn = dtMaterialLot.Columns(i)
            Select Case dc.ColumnName
                Case "EquipmentNo", "MaterialNo", "SubstituteMaterialNo", "MaterialLotNo", "UseQty"
                Case Else
                    dtMaterialLot.Columns.RemoveAt(i)
            End Select
        Next

        If Not dtMaterialLot.Columns.Contains("LotNo") Then dtMaterialLot.Columns.Add("LotNo", GetType(String))
        dtMaterialLot.Columns("MaterialNo").ColumnName = "OrgMaterialNo"
        dtMaterialLot.Columns("SubstituteMaterialNo").ColumnName = "MaterialNo"
        dtMaterialLot.Columns("UseQty").ColumnName = "Qty"

        For Each dr As DataRow In dtMaterialLot.Rows
            dr("LotNo") = LotNo
        Next

    End Sub
    '2019/07/12 Eric
    Private Function funCombineT100InXml(ByVal FromProductNo As String, ByVal MONo As String)

        Dim code As String = String.Empty
        Dim sqlcode As String = String.Empty
        Dim description As String = String.Empty

        Dim XmlDoc As New XmlDocument()
        Dim dtUnionProduct As DataTable
        Dim arriveTime As DateTime = Now

        Try
            '組InXml的字串
            strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
            strParameter = CombineXMLParameter("ProductNo", "ProductNo", "String", FromProductNo, "")
            strParameter += CombineXMLParameter("mono", "MONo", "String", MONo, "")
            InXml = CombineXMLRequest(strIdentity, strParameter)

            OutXml = InvokeSrv("wsERP_T100.ERP_Joint_Product_Get", InXml)

            XmlDoc.LoadXml(OutXml)

            code = XmlDoc.GetElementsByTagName("execution").Item(0).SelectNodes("status").Item(0).Attributes("code").Value
            description = XmlDoc.GetElementsByTagName("execution").Item(0).SelectNodes("status").Item(0).Attributes("description").Value
            If code <> "0" Then
                If description <> String.Empty Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Return Message%]" & vbCrLf & description), MsgBoxStyle.Exclamation, Me.Text)
                Else
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Fail%]"), MsgBoxStyle.Exclamation, Me.Text)
                End If
                Exit Function
            End If

            Dim dtUProduct As New DataTable("UnionProductData")
            dtUProduct = New DataTable("UnionProductData")
            dtUProduct.DefaultView.AllowNew = False
            dtUProduct.DefaultView.AllowDelete = False
            dtUProduct.DefaultView.AllowEdit = True
            '建立UnionProductData Table的欄位
            dtUProduct.Columns.Add("UnionProductNo", System.Type.GetType("System.String"))
            dtUProduct.Columns.Add("UnionProductUnit", System.Type.GetType("System.String"))

            Dim drPRD As DataRow
            Dim item_no As String
            Dim unit_no As String
            Dim iCount As Integer = XmlDoc.GetElementsByTagName("row").Count - 1

            For i As Integer = 1 To iCount
                item_no = XmlDoc.DocumentElement.GetElementsByTagName("row").Item(i).SelectNodes("field").Item(0).InnerXml
                unit_no = XmlDoc.DocumentElement.GetElementsByTagName("row").Item(i).SelectNodes("field").Item(1).InnerXml
                drPRD = dtUProduct.NewRow()
                drPRD("UnionProductNo") = item_no
                drPRD("UnionProductUnit") = unit_no
                dtUProduct.Rows.Add(drPRD)
            Next

            '取得ERP回傳之聯產品資訊
            dtUnionProduct = dtUProduct

            If dtUnionProduct.DefaultView.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP DID NOT RETURN THE JOINT PRODUCT INFORMATION%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            End If

            '開窗給使用者選擇
            Cursor.Current = Cursors.WaitCursor

            Dim fSearch As New frmCOMSearch
            fSearch.dvSearch = dtUnionProduct.DefaultView
            fSearch.strFindColumnName = "UnionProductNo"
            '20221214,13871,右鍵 儲存設計 需要使用Owner(程式碼由程序建立)
            fSearch.ShowDialog(Me)
            fSearch.Dispose()

            If drSearch Is Nothing Then Exit Function

            '檢查聯產品資料是否存在系統中以及是否有版本資訊
            funLoadProduct(drSearch("UnionProductNo").ToString.ToUpper, False)

            If dsWIP.Tables(tblProductBasis).Rows.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & ""), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("IssueState") <> 2 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%EDATA%][%Unfrozen%] "), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString <> dsWIP.Tables(tbllotbasis).Rows(0)("ProductVersion").ToString Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%NOTHINGSTATE%][%CURVERSION%][%PRODUCTINFO%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            Else
                txtUnionProductNo.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductNo").ToString
                txtUnionProductVersion.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString
                txtUnionProductUnit.Text = dsWIP.Tables(tblProductBasis).Rows(0)("UnitNo").ToString

                '選取聯產品資訊時, 需自動勾起聯產品checkBox
                chkUnionProductNo.Checked = True
            End If

            Cursor.Current = Cursors.Default

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally

            '紀錄TransactionLog
            addTransactionLog_ErrorCode(InXml, OutXml, arriveTime.ToString("yyyyMMddHHmmssss"), "WIP", "ERP_Joint_Product_Get", My.Computer.Name, gUserNo, arriveTime.ToString("yyyy/MM/dd HH:mm:ss"), code, "", "ERP_Joint_Product_Get", LogClass:="WIP")
        End Try

    End Function

    '87580: [605]iMES與E10整合_第一階段_SDD210205_01-09取得E10聯產品資料
    Private Function funCombineE10ICDInXml(ByVal FromProductNo As String, ByVal MONo As String)

        Dim code As String = String.Empty
        Dim sqlcode As String = String.Empty
        Dim description As String = String.Empty

        Dim XmlDoc As New XmlDocument()
        Dim dtUnionProduct As DataTable
        Dim arriveTime As DateTime = Now

        Try
            '組InXml的字串
            strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
            strParameter = CombineXMLParameter("ProductNo", "ProductNo", "String", FromProductNo, "")
            strParameter += CombineXMLParameter("mono", "MONo", "String", MONo, "")
            InXml = CombineXMLRequest(strIdentity, strParameter)

            OutXml = InvokeSrv("wsERP_E10ICD.ERP_Joint_Product_Get", InXml)

            XmlDoc.LoadXml(OutXml)

            code = XmlDoc.GetElementsByTagName("execution").Item(0).SelectNodes("status").Item(0).Attributes("code").Value
            description = XmlDoc.GetElementsByTagName("execution").Item(0).SelectNodes("status").Item(0).Attributes("description").Value
            If code <> "0" Then
                If description <> String.Empty Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Return Message%]" & vbCrLf & description), MsgBoxStyle.Exclamation, Me.Text)
                Else
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP Fail%]"), MsgBoxStyle.Exclamation, Me.Text)
                End If
                Exit Function
            End If

            Dim dtUProduct As New DataTable("UnionProductData")
            dtUProduct = New DataTable("UnionProductData")
            dtUProduct.DefaultView.AllowNew = False
            dtUProduct.DefaultView.AllowDelete = False
            dtUProduct.DefaultView.AllowEdit = True
            '建立UnionProductData Table的欄位
            dtUProduct.Columns.Add("UnionProductNo", System.Type.GetType("System.String"))
            dtUProduct.Columns.Add("UnionProductUnit", System.Type.GetType("System.String"))

            Dim drPRD As DataRow
            Dim item_no As String
            Dim unit_no As String
            Dim iCount As Integer = XmlDoc.GetElementsByTagName("row").Count - 1

            For i As Integer = 1 To iCount
                item_no = XmlDoc.DocumentElement.GetElementsByTagName("row").Item(i).SelectNodes("field").Item(0).InnerXml
                unit_no = XmlDoc.DocumentElement.GetElementsByTagName("row").Item(i).SelectNodes("field").Item(1).InnerXml
                drPRD = dtUProduct.NewRow()
                drPRD("UnionProductNo") = item_no
                drPRD("UnionProductUnit") = unit_no
                dtUProduct.Rows.Add(drPRD)
            Next

            '取得ERP回傳之聯產品資訊
            dtUnionProduct = dtUProduct

            If dtUnionProduct.DefaultView.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ERP DID NOT RETURN THE JOINT PRODUCT INFORMATION%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            End If

            '開窗給使用者選擇
            Cursor.Current = Cursors.WaitCursor

            Dim fSearch As New frmCOMSearch
            fSearch.dvSearch = dtUnionProduct.DefaultView
            fSearch.strFindColumnName = "UnionProductNo"
            '20221214,13871,右鍵 儲存設計 需要使用Owner(程式碼由程序建立)
            fSearch.ShowDialog(Me)
            fSearch.Dispose()

            If drSearch Is Nothing Then Exit Function

            '檢查聯產品資料是否存在系統中以及是否有版本資訊
            funLoadProduct(drSearch("UnionProductNo").ToString.ToUpper, False)

            If dsWIP.Tables(tblProductBasis).Rows.Count = 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & ""), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("IssueState") <> 2 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%EDATA%][%Unfrozen%] "), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            ElseIf dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString <> dsWIP.Tables(tbllotbasis).Rows(0)("ProductVersion").ToString Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-202106", "[%ProductNo%] : " & drSearch("UnionProductNo").ToString & " [%NOTHINGSTATE%][%CURVERSION%][%PRODUCTINFO%]"), MsgBoxStyle.Exclamation, Me.Text)
                Exit Function
            Else
                txtUnionProductNo.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductNo").ToString
                txtUnionProductVersion.Text = dsWIP.Tables(tblProductBasis).Rows(0)("ProductVersion").ToString
                txtUnionProductUnit.Text = dsWIP.Tables(tblProductBasis).Rows(0)("UnitNo").ToString

                '選取聯產品資訊時, 需自動勾起聯產品checkBox
                chkUnionProductNo.Checked = True
            End If

            Cursor.Current = Cursors.Default

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally

            '紀錄TransactionLog
            addTransactionLog_ErrorCode(InXml, OutXml, arriveTime.ToString("yyyyMMddHHmmssss"), "WIP", "ERP_Joint_Product_Get", My.Computer.Name, gUserNo, arriveTime.ToString("yyyy/MM/dd HH:mm:ss"), code, "", "ERP_Joint_Product_Get", LogClass:="WIP")
        End Try

    End Function


#End Region

#Region "用料機制"

    ''' <summary>
    ''' 2016/10/20 YF, 取出上料資訊
    ''' </summary>
    ''' <returns></returns>
    Private Function GetFeedingData() As Boolean

        Dim result As Boolean = False

        ' 2016/10/20 YF, 依作業站用料選項處理用料機制
        Select Case dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString
            Case "0"
                ' 發料點(線邊倉或工單)
                'result = GetFeedingByPutinPlace()
                btnKeyIn.Visible = True
                txtMaterialNo.Enabled = True
                txtMaterialLotNo.Enabled = True
                result = True
            Case "1"
                ' 設備
                blnByEQP = True
                GetFeedingByEQP()
                txtMaterialNo.Enabled = False
                txtMaterialLotNo.Enabled = False
            Case "2"
                ' 生產線, 待組裝版再實作
            Case "3"
                ' 工位, 待組裝版再實作
            Case Else
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-003000", "[%MaterialOption%]：" & dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString & " [%NOT DEFINE%]!"), MsgBoxStyle.Exclamation, Me.Text)
        End Select

        Return result

    End Function

#End Region

#Region "發料點上料資訊"

    ''' <summary>
    ''' 2016/10/27 YF, 在物料區刷入物料及料批號, 自動從投料點帶出物料資訊, 從txtMaterialLotNo_KeyPress搬移過來
    ''' Gary Lu 20131104~06:增加先刷入物料編號再刷入物料批號的方式
    ''' 並修改成刷入物料料批批量小於總標準用量時，仍可自動帶入，惟帶入用量為該料批之批量
    ''' </summary>
    ''' <returns></returns>

    Private Sub AutoFeedingByPutinPlace(ByVal strMaterialNo As String, ByVal strMaterialLotNo As String)

        Try
            '不須用料
            If dsWIP.Tables(tblTMaterial) Is Nothing OrElse
                dsWIP.Tables(tblTMaterial).Rows.Count = 0 Then Exit Sub

            If strMaterialNo.Trim = "" Then Exit Sub
            If strMaterialLotNo.Trim = "" Then Exit Sub

            Dim drMLot() As DataRow = dtMLot.Select("SubstituteMaterialNo = '" & strMaterialNo & "' And MaterialLotNo = '" & strMaterialLotNo & "'")
            If drMLot.Length > 0 Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(
                    ChgTranslateName_Msg("0000-200004", "[%MaterialNo%]: " & strMaterialNo & vbCrLf &
                    "[%MaterialLotNo%]: " & strMaterialLotNo), MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If

            Dim drMaterialLotData As DataRow = Nothing
            For Each drTMaterial As DataRow In dsWIP.Tables(tblTMaterial).Rows
                drMaterialLotData = funGetMateriallLotData(strMaterialNo, strMaterialLotNo, drTMaterial)
                If IsNothing(drMaterialLotData) Then Continue For

                funAddNewMlot(drMaterialLotData, drTMaterial)
                funUpdateSumUseQty(drTMaterial)
                Exit For
            Next

            If IsNothing(drMaterialLotData) Then
                iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(
                    ChgTranslateName_Msg("0000-202104", "[%MaterialNo%]:" & strMaterialNo & ", [%MaterialLotNo%]: " & strMaterialLotNo),
                    MsgBoxStyle.Exclamation, Me.Text)
                Exit Sub
            End If

            txtMaterialLotNo.Text = ""
            txtMaterialNo.Text = ""
            txtMaterialNo.Focus()

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally
            Cursor.Current = Cursors.Default
        End Try

    End Sub
    Private Sub funUpdateSumUseQty(ByVal drTMaterial As DataRow)

        Dim SumQty As Decimal = 0
        For Each drMLot As DataRow In dtMLot.Rows
            If drMLot("MaterialNo") = drTMaterial("MaterialNo") Then
                SumQty += (drMLot("UseQty") * (drTMaterial("StdQty") / drMLot("SubstituteStdQty")))
            End If
        Next

        drTMaterial.BeginEdit()
        drTMaterial("UseQty") = Format(SumQty, "0.########")
        drTMaterial.EndEdit()
    End Sub
    Private Sub funAddNewMlot(ByVal drMaterialLot As DataRow, ByVal drTMaterial As DataRow)

        Dim drAddMLot As DataRow
        drAddMLot = dtMLot.NewRow
        drAddMLot("EquipmentNo") = drMaterialLot("EquipmentNo")
        drAddMLot("MaterialNo") = drTMaterial("MaterialNo")
        drAddMLot("MaterialLotNo") = drMaterialLot("MaterialLotNo")
        drAddMLot("Qty") = drMaterialLot("Qty")
        drAddMLot("UseQty") = funCalculateUseQty(drTMaterial, drMaterialLot)
        drAddMLot("SubstituteMaterialNo") = drMaterialLot("MaterialNo")
        drAddMLot("SubstituteMaterialLevel") = drMaterialLot("SubstituteMaterialLevel")
        drAddMLot("SubstituteMaterialType") = drMaterialLot("SubstituteMaterialType")
        drAddMLot("SubstituteStdQty") = drMaterialLot("SubstituteStdQty")
        drAddMLot("CheckLotNo") = drMaterialLot("CheckLotNo")
        dtMLot.Rows.Add(drAddMLot)

    End Sub

    'CHECKLXL
    Private Function funLoadStuInfo() As Integer

        funLoadStuInfo = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        'UNCHECK
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("ABC.wsWIP_21685.LoadStuInfoByLotNo", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '讀取取出資料表之名稱
                tblStuInfo = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("lodastudentinfobylotno").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("lodastudentinfobylotno").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("lodastudentinfobylotno").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                dsWIP.Tables(tblStuInfo).DefaultView.Sort = "StudentNo"
                iugStuInfo.iMESUltraGrid.DataSource = dsWIP.Tables(tblStuInfo).DefaultView
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funLoadStuInfo = 0

    End Function

    'CHECKLXL
    Private Sub iugStudentInfo_iMESUltraGrid_InitializeLayOut(sender As Object, e As InitializeLayoutEventArgs) Handles iugStuInfo.iMESUltraGrid_InitializeLayOut
        Dim i As Integer

        With e.Layout
            For i = 0 To dsWIP.Tables(tblStuInfo).Columns.Count - 1
                Select Case dsWIP.Tables(tblStuInfo).Columns(i).ColumnName.ToUpper
                    Case "STUDENTNO"
                        With .Bands(tblStuInfo).Columns("StudentNo")
                            .Header.Caption = "StudentNo"
                            .Width = 120
                            .Header.VisiblePosition = 1
                        End With
                    Case "STUDENTNAME"
                        With .Bands(tblStuInfo).Columns("StudentName")
                            .Header.Caption = "StudentName"
                            .Width = 120
                            .Header.VisiblePosition = 2
                        End With
                    Case "ISSELECTED"
                        With .Bands(tblStuInfo).Columns("IsSelected")
                            .Header.Caption = "IsSelected"
                            .Width = 120
                            .Header.VisiblePosition = 3
                            .ValueList = vlStuInfoIsSelected
                        End With
                    Case "LOTNO"
                        With .Bands(tblStuInfo).Columns("LotNo")
                            .Header.Caption = "LotNo"
                            .Width = 120
                            .Header.VisiblePosition = 4
                        End With
                    Case Else
                        With .Bands(tblStuInfo).Columns(dsWIP.Tables(tblStuInfo).Columns(i).ColumnName.ToUpper)
                            .Hidden = True
                        End With
                End Select
            Next
        End With
    End Sub

    Private Function funGetMateriallLotData(ByVal strMaterialNo As String, ByVal strMaterialLotNo As String, ByVal drTMaterial As DataRow) As DataRow

        If funLoadSubstituteMaterial_Main(drTMaterial("MaterialNo"), drTMaterial("UnitNo")) >= 0 Then
            Dim drSel As DataRow() =
                dsWIP.Tables(tblSubstituteMaterial).Select("MaterialNo='" & strMaterialNo & "' and MaterialLotNo = '" & strMaterialLotNo & "'")

            If drSel.Length > 0 Then Return drSel(0)
        End If

        Return Nothing

    End Function
    Private Function funCalculateUseQty(ByVal drTMaterial As DataRow, ByVal drMateriallLot As DataRow) As Decimal
        '判断当前物理与当前用料是否一致 不一致直接返回0
        If drMateriallLot("MaterialNo").ToString <> drTMaterial("MaterialNo").ToString Then
            Return 0
        End If
        Dim MaterialNo As String = drTMaterial("MaterialNo").ToString

        '總共需要的主料數量
        Dim StdUseQty As Decimal = drTMaterial("StdUseQty")
        '做一個成品需要的主料數量
        Dim StdQty As Decimal = drTMaterial("StdQty")

        '計算還需要多少主料
        Dim RemainingQty As Decimal = funGetRemainingQty(StdUseQty, StdQty, MaterialNo)

        '單位轉成替代料
        RemainingQty = RemainingQty * (drMateriallLot("SubstituteStdQty") / StdQty)

        If RemainingQty <= 0 Then Return 0

        '料批數量不足 則使用料批數量就好
        If drMateriallLot("Qty") < RemainingQty Then
            Return drMateriallLot("Qty")
        End If

        Return RemainingQty

    End Function
    ''' <summary>
    ''' 計算還需要多少主料
    ''' </summary>
    Private Function funGetRemainingQty(ByVal StdUseQty As Decimal, ByVal StdQty As Decimal, ByVal MaterialNo As String) As Decimal

        Dim drSel As DataRow() = dtMLot.Select("MaterialNo = '" & MaterialNo & "'")
        For Each drMLot In drSel
            StdUseQty -= (drMLot("UseQty") * (StdQty / drMLot("SubstituteStdQty")))
        Next

        Return StdUseQty

    End Function

#End Region

#Region "設備上料資訊"

    ''' <summary>
    ''' 2016/10/21 YF, 取得設備上料資訊
    ''' </summary>
    ''' <returns></returns>
    Private Sub GetFeedingByEQP()

        Dim EquipmentNo As String = ""
        Dim XmlDoc As New XmlDocument
        Dim dsTemp As New DataSet
        Dim drAdd As DataRow

        Try

            ' 設備編號 
            If (dsWIP.Tables(tblTEquipment) Is Nothing) OrElse (dsWIP.Tables(tblTEquipment).Rows.Count = 0) Then
                Throw New iMESException.MESException("0000-200003", "[%MATERIALOPTIONISEQP%], [%MUSTSELECTEQP%]!")
            End If

            For Each r As DataRow In dsWIP.Tables(tblTEquipment).Rows
                EquipmentNo += "|" & r("EquipmentNo").ToString
            Next
            If EquipmentNo <> "" Then
                EquipmentNo = Mid(EquipmentNo, 2)
            End If

            'EquipmentNo = dsWIP.Tables(tblTEquipment).Rows(0)("EquipmentNo").ToString

            '組InXml的字串
            strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
            strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
            strParameter += CombineXMLParameter("opno", "OPNo", "String", dsWIP.Tables(tblLotState).Rows(0)("OPNo"), "")
            strParameter += CombineXMLParameter("equipmentno", "EquipmentNo", "String", EquipmentNo, "")
            InXml = CombineXMLRequest(strIdentity, strParameter)

            OutXml = InvokeSrv("wsWIP_Material.LoadFeedingByEquipment", InXml)

            XmlDoc.LoadXml(OutXml)

            If Not ChkExecutionSuccess(XmlDoc) Then
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If

            '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
            XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadfeedingbyequipment").Item(0).SelectNodes("schema").Item(0).InnerXml

            If XmlSchema <> "" Then
                '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                tmpStringReader = New System.IO.StringReader(XmlSchema)
                dsTemp.ReadXmlSchema(tmpStringReader)
                tmpStringReader.Close()
            End If

            '取出Data
            XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadfeedingbyequipment").Item(0).SelectNodes("value").Item(0).InnerXml

            If XmlData <> "" Then
                tmpStringReader = New System.IO.StringReader(XmlData)
                dsTemp.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                tmpStringReader.Close()
            End If

            dtMLot.Clear()

            Dim iCount As Decimal
            Dim drSel As DataRow()
            Dim strConditionMtl As String = ""
            For Each r1 As DataRow In dsWIP.Tables(tblTMaterial).Rows
                strConditionMtl = ""
                ' 判斷是否有上料
                Dim strSelectCondition As String = ""
                If r1("PutInPlaceType") = 3 Then
                    strSelectCondition = " And MONo = '" & dsWIP.Tables(tblLotState).Rows(0)("MONo").ToString & "' "
                ElseIf r1("PutInPlaceType") = 2 OrElse r1("PutInPlaceType") = 4 Then
                    strSelectCondition = " And MONo = 'N/A'"
                End If

                '新设备上料 根据用料清单找到可以使用的物料
                drSel = dsOE.Tables(strMOList).Select("MaterialNo = '" & r1("MaterialNo") & "'")
                For Each dr As DataRow In drSel
                    strConditionMtl += "'" & dr("SubstituteMaterialNo") & "'" + ","
                Next
                strConditionMtl = strConditionMtl.Substring(0, strConditionMtl.Length - 1)
                'dsTemp.Tables(0).DefaultView.RowFilter = "MaterialNo = '" & r1("MaterialNo") & "' And Qty > 0" & strSelectCondition
                dsTemp.Tables(0).DefaultView.RowFilter = "InputMaterialNo in (" & strConditionMtl & ") And Qty > 0" & strSelectCondition
                dsTemp.Tables(0).DefaultView.Sort = "SEQ"



                'iCount = dsTemp.Tables(0).DefaultView.Count
                'Dim Num As Decimal
                ''Dim Remainder As Decimal
                'If iCount <> 0 Then
                '    Num = Format(Convert.ToDecimal(RemainingQty / iCount), "0.########")
                '    'Remainder = RemainingQty Mod iCount
                'End If

                Dim sumRemainingQty As Decimal = 0
                ' 將上料資訊寫入dtMLot
                For Each r2 As DataRowView In dsTemp.Tables(0).DefaultView
                    drAdd = dtMLot.NewRow
                    drAdd("EquipmentNo") = r2("EquipmentNo")
                    'drAdd("MaterialNo") = r2("MaterialNo") '因为上料表中的materialno是* 则取工单用料清单的主料 新设备上料 14278
                    drAdd("MaterialNo") = r1("MaterialNo")
                    drAdd("MaterialLotNo") = r2("MaterialLotNo")
                    drAdd("Qty") = r2("Qty")
                    drAdd("UseQty") = 0
                    drAdd("SubstituteMaterialNo") = r2("InputMaterialNo")
                    drAdd("SubstituteMaterialLevel") = r2("SubstituteMaterialLevel")
                    drAdd("SubstituteMaterialType") = r2("SubstituteMaterialType")
                    drAdd("SubstituteStdQty") = r2("SubstituteStdQty")
                    drAdd("CheckLotNo") = r2("CheckLotNo")
                    drAdd("AccDate") = r2("AcclimationDate")            '回溫時間
                    dtMLot.Rows.Add(drAdd)
                Next

                For Each drMLot As DataRow In dtMLot.Rows
                    If drMLot("UseQty") <= 0 Then
                        drMLot("UseQty") = funCalculateUseQty(r1, drMLot)
                    End If
                Next

                funUpdateSumUseQty(r1)
            Next

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally
            XmlDoc = Nothing
        End Try

    End Sub

    ''' <summary>
    ''' 2016/10/27 YF, 自動上料 - 設備
    ''' </summary>
    ''' <returns></returns>
    Private Function AutoFeedingByEQP() As Boolean

        Dim result As Boolean = False
        Dim EquipmentNo As String
        Dim ActiveRow As UltraGridRow
        Dim XmlDoc As New XmlDocument
        Dim FeedingQty As Decimal

        Try

            Cursor.Current = Cursors.WaitCursor

            ' 設備編號 
            If (dsWIP.Tables(tblTEquipment) Is Nothing) OrElse (dsWIP.Tables(tblTEquipment).Rows.Count = 0) Then
                Throw New iMESException.MESException("0000-200003", "[%MATERIALOPTIONISEQP%], [%MUSTSELECTEQP%]!")
            End If

            EquipmentNo = dsWIP.Tables(tblTEquipment).Rows(0)("EquipmentNo").ToString

            ' 檢查是否有選定一筆物料
            If (Me.iugMaterial.iMESUltraGrid.ActiveRow Is Nothing) OrElse (Not Me.iugMaterial.iMESUltraGrid.ActiveRow.IsDataRow) Then
                Throw New iMESException.MESException("0000-003000", "[%PLEASE SELECT%] [%MATERIAL%]!")
            Else
                ActiveRow = Me.iugMaterial.iMESUltraGrid.ActiveRow
            End If

            ' 若目前作用中的資料列是子資料, 則先將父資料設為ActiveRow
            If (Not ActiveRow.ParentRow Is Nothing) Then
                Me.iugMaterial.iMESUltraGrid.ActiveRow = ActiveRow.ParentRow
                ActiveRow = Me.iugMaterial.iMESUltraGrid.ActiveRow
            End If

            ' 檢查有無輸入料號
            If (Me.txtMaterialNo.Text = "") Then
                Me.txtMaterialNo.Focus()
                Throw New iMESException.MESException("0000-200001", "[%MATERIALNO%]!")
            End If

            ' 檢查有無輸入料批
            If (Me.txtMaterialLotNo.Text = "") Then
                Me.txtMaterialLotNo.Focus()
                Throw New iMESException.MESException("0000-200001", "[%MATERIALLOTNO%]!")
            End If

            ' 2016/11/03 YF, 自動上料時, 應將工單或線邊倉目前數量全數上到設備
            FeedingQty = GetMaterialFeedingQty(ActiveRow)

            ' 進行設備上料
            strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
            strParameter = CombineXMLParameter("equipmentno", "EquipmentNo", "String", CInput(EquipmentNo), "")
            strParameter += CombineXMLParameter("materialno", "MaterialNo", "String", CInput(ActiveRow.Cells("MaterialNo").Value), "")
            strParameter += CombineXMLParameter("checklotno", "CheckLotNo", "String", CInput(ActiveRow.Cells("CheckLotNo").Value), "")
            strParameter += CombineXMLParameter("mono", "MONo", "String", CInput(txtMONo.Text), "")
            strParameter += CombineXMLParameter("inputmaterialno", "InputMaterialNo", "String", CInput(Me.txtMaterialNo.Text), "")
            strParameter += CombineXMLParameter("materiallotno", "MaterialLotNo", "String", CInput(Me.txtMaterialLotNo.Text), "")
            strParameter += CombineXMLParameter("inputqty", "InputQty", "Decimal", FeedingQty, "")
            strParameter += CombineXMLParameter("userno", "UserNo", "String", CInput(gUserNo), "")
            strParameter += CombineXMLParameter("revisedate", "ReviseDate", "DateTime", Format(Now, "yyyy/MM/dd HH:mm:ss"), "")

            ' 因CInput的參數是ByRef, 所以會造成UltraGrid的ActiveRow變成編輯狀況(有一支筆的圖示出現)
            ActiveRow.CancelUpdate()

            InXml = CombineXMLRequest(strIdentity, strParameter)

            OutXml = InvokeSrv("wsWIP_Material.Exe_EQPMountMaterial", InXml)

            XmlDoc.LoadXml(OutXml)

            If ChkExecutionSuccess(XmlDoc) Then
                Me.txtMaterialNo.Text = ""
                Me.txtMaterialLotNo.Text = ""
                Me.txtMaterialNo.Focus()
                ' 上料成功後重新取出上料資訊
                GetFeedingByEQP()
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            result = True

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        Finally
            XmlDoc = Nothing
            Cursor.Current = Cursors.Default
        End Try

        Return result

    End Function

#End Region

#Region "取出物料要上料的數量"

    ''' <summary>
    ''' 2016/11/03 YF, 取出要上料的數量
    ''' 工單發料: pPutinNo即為工單編號
    ''' 線邊倉發料: pPutinNo即為庫房編號
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetMaterialFeedingQty(ByVal row As UltraGridRow) As Decimal

        Dim FeedingQty As Decimal = 0
        Dim dsTemp As New DataSet
        Dim XmlDoc As New XmlDocument
        Dim TagName As String
        Dim ErrorCode As String
        Dim InventoryNo As String
        Dim ErrorMessage As String

        Try

            strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())

            If (row.Cells("PutinPlaceType").Value = 3) Then
                ' 工單發料
                strParameter = CombineXMLParameter("mono", "MONo", "String", CInput(Me.txtMONo.Text), "")
                strParameter += CombineXMLParameter("materialno", "MaterialNo", "String", CInput(row.Cells("MaterialNo").Value), "")
                strParameter += CombineXMLParameter("materiallotno", "MaterialLotNo", "String", CInput(Me.txtMaterialLotNo.Text), "")
                InXml = CombineXMLRequest(strIdentity, strParameter)
                OutXml = InvokeSrv("wsOE.LoadMOMaterialState", InXml)
                TagName = "loadmomaterialstate"
                ErrorCode = "9P12-200026"
                ErrorMessage = "[%MONO%]: " & Me.txtMONo.Text
            ElseIf (row.Cells("PutinPlaceType").Value = 2) Then
                ' 線邊倉發料
                ' 取出倉庫編號
                InventoryNo = GetInventoryNo()
                strParameter = CombineXMLParameter("inventoryno", "InventoryNo", "String", CInput(InventoryNo), "")
                strParameter += CombineXMLParameter("materiallotno", "MaterialLotNo", "String", CInput(Me.txtMaterialLotNo.Text), "")
                InXml = CombineXMLRequest(strIdentity, strParameter)
                OutXml = InvokeSrv("wsINV.LoadWIPInventory_Raw", InXml)
                TagName = "loadwipinventory_raw"
                ErrorCode = "0000-202103"
                ErrorMessage = "[%INVENTORYNO%]: " & InventoryNo & " "
            Else
                Throw New iMESException.MESException("0000-003000", "[%PutinPlaceType%]: " & row.Cells("PutinPlaceType").Value & ", [%NOT DEFINE%]!")
            End If

            XmlDoc.LoadXml(OutXml)

            If ChkExecutionSuccess(XmlDoc) Then

                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName(TagName).Item(0).SelectNodes("schema").Item(0).InnerXml

                If XmlSchema <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsTemp.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If

                XmlData = XmlDoc.DocumentElement.GetElementsByTagName(TagName).Item(0).SelectNodes("value").Item(0).InnerXml

                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsTemp.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                If (dsTemp.Tables.Count > 0) AndAlso (dsTemp.Tables(0).Rows.Count > 0) Then

                    If (dsTemp.Tables(0).Rows(0)("Qty") > 0) Then
                        FeedingQty = dsTemp.Tables(0).Rows(0)("Qty")
                    Else
                        Throw New iMESException.MESException(ErrorCode,
                                                             "[%MaterialNo%]: " & row.Cells("MaterialNo").Value & vbCrLf &
                                                             "[%MaterialLotNo%]: " & Me.txtMaterialLotNo.Text & vbCrLf &
                                                             "[%QUANTITY%] [%IS EQUAL TO%] 0!")
                    End If

                Else
                    Throw New iMESException.MESException("0000-200003",
                                                         ErrorMessage & vbCrLf &
                                                         "[%MaterialNo%]: " & row.Cells("MaterialNo").Value & vbCrLf &
                                                         "[%MaterialLotNo%]: " & Me.txtMaterialLotNo.Text)

                End If

            Else
                Throw New iMESException.MESException(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc))
            End If

        Catch ex As iMESException.MESException
            Throw
        Catch ex As Exception
            Throw
        Finally
            dsTemp = Nothing
            XmlDoc = Nothing
        End Try

        Return FeedingQty

    End Function

    ''' <summary>
    ''' 2016/11/03 YF, 取出倉庫
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetInventoryNo() As String

        Dim result As String = ""
        Dim dsTemp As New DataSet
        Dim XmlDoc As New XmlDocument

        Try

            strParameter = CombineXMLParameter("areano", "AreaNo", "String", CInput(Me.txtAreaNo.Text), "")
            InXml = CombineXMLRequest(strIdentity, strParameter)
            OutXml = InvokeSrv("wsSMD.LoadAreaInventory", InXml)

            XmlDoc.LoadXml(OutXml)

            If ChkExecutionSuccess(XmlDoc) Then

                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadareainventory").Item(0).SelectNodes("schema").Item(0).InnerXml

                If XmlSchema <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsTemp.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If

                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadareainventory").Item(0).SelectNodes("value").Item(0).InnerXml

                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsTemp.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If

                If (dsTemp.Tables.Count > 0) AndAlso (dsTemp.Tables(0).Rows.Count > 0) Then
                    dsTemp.Tables(0).DefaultView.Sort = "DefaultInv Desc"
                    result = dsTemp.Tables(0).DefaultView(0)("InventoryNo")
                Else
                    Throw New iMESException.MESException("0000-202111", "[%AreaNo%]: " & Me.txtAreaNo.Text)
                End If

            Else
                Throw New iMESException.MESException(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc))
            End If


        Catch ex As iMESException.MESException
            Throw
        Catch ex As Exception
            Throw
        Finally
            dsTemp = Nothing
            XmlDoc = Nothing
        End Try

        Return result

    End Function

#End Region

#Region "作業人員"

    ''' <summary>
    ''' 2016/12/26 YF, 顯示作業人員現況資訊
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnOperator_Click(sender As Object, e As EventArgs) Handles btnOperator.Click

        Dim parameters As Dictionary(Of String, Object)
        Dim EquipmentNo As String = ""

        Try

            parameters = New Dictionary(Of String, Object)

            With dsWIP.Tables(tblLotState).Rows(0)

                Select Case .Item("MultiOperatorMode").ToString
                    Case "0"
                        ' 作業站
                        parameters.Add("OPNo", .Item("OPNo").ToString)
                    Case "1"
                        ' 區域
                        parameters.Add("AreaNo", .Item("AreaNo").ToString)
                    Case "2"
                        ' 設備 
                        If (dsWIP.Tables(tblTEquipment) Is Nothing) OrElse (dsWIP.Tables(tblTEquipment).Rows.Count = 0) Then
                            Throw New iMESException.MESException("0000-103010", "[%PLEASE SELECT%] [%EQUIPMENT%]!")
                        End If

                        For Each row As DataRow In dsWIP.Tables(tblTEquipment).Rows
                            EquipmentNo += row("EquipmentNo") & ","
                        Next

                        EquipmentNo = EquipmentNo.TrimEnd(",")
                        parameters.Add("EquipmentNo", EquipmentNo)

                    Case "5" 'Mantis 63873: 增加判斷多人加工模式為生產批, 並傳入資料
                        ' 生產批
                        parameters.Add("LotNo", .Item("LotNo").ToString)
                    Case Else
                        Throw New iMESException.MESException("0000-003000", "[%MultiOperatorMode%]:" & .Item("MultiOperatorMode").ToString & " [%NOT DEFINE%]!")
                End Select

            End With

            parameters.Add("EnableSignOut", False)
            Me.ObjectFileHandler.Execute(pObjectID:="WP_OperatorOnline", pParameters:=parameters)

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub

#End Region

#Region "特殊生產需求"

    '2019/01/19 Eric 特殊生產需求顯示
    Private Sub btnSWR_Click(sender As System.Object, e As System.EventArgs) Handles btnSWR.Click

        '2019/02/12 Eric 加入判斷有無資料
        If blnShowSWR = True Then

            Dim Parameters As New Dictionary(Of String, Object)
            Parameters.Add("MONo", txtMONo.Text)
            Parameters.Add("CustomerLotNo", txtCustomerLotNo.Text)
            Parameters.Add("OPNo", txtOPNo.Text)
            Parameters.Add("LotNo", txtLotNo.Text)
            Parameters.Add("DeviceNo", dsWIP.Tables(tblLotState).Rows(0)("DeviceNo").ToString)
            Parameters.Add("CustomerNo", dsWIP.Tables(tblLotState).Rows(0)("CustomerNo").ToString)
            Parameters.Add("LogGroupSerial", dsWIP.Tables(tblLotState).Rows(0)("LogGroupSerial").ToString)
            Parameters.Add("blnCICo", True)
            Me.ObjectFileHandler.Execute("WP_SWRBasisRead", Parameters)

            btnSWR.Visible = True

        End If

    End Sub

    '2019/02/12 Eric 
    Private Sub funLoadSWRJoinLog()

        Cursor.Current = Cursors.WaitCursor


        If Not IsNothing(dsWIP.Tables(tblSWRJoinLog)) Then
            dsWIP.Tables.Remove(tblSWRJoinLog)
        End If

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("loggroupserial", "LogGroupSerial", "String", CInput(dsWIP.Tables(tblLotState).Rows(0)("LogGroupSerial").ToString), "")
        strParameter += CombineXMLParameter("customerno", "CustomerNo", "String", CInput(dsWIP.Tables(tblLotState).Rows(0)("CustomerNo").ToString), "")
        strParameter += CombineXMLParameter("lotno", "LotNo", "String", CInput(txtLotNo.Text), "")
        strParameter += CombineXMLParameter("deviceno", "DeviceNo", "String", CInput(dsWIP.Tables(tblLotState).Rows(0)("DeviceNo").ToString), "")
        strParameter += CombineXMLParameter("opno", "OPNo", "String", CInput(txtOPNo.Text), "")
        strParameter += CombineXMLParameter("customerlotno", "CustomerLotNo", "String", CInput(txtCustomerLotNo.Text), "")
        strParameter += CombineXMLParameter("mono", "MONo", "String", CInput(txtMONo.Text), "")
        strParameter += CombineXMLParameter("status", "Status", "Integer", 2, "")

        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try

            OutXml = InvokeSrv("wsWIP.LoadSWRBasisJoinLog", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                tblSWRJoinLog = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadswrbasisjoinlog").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadswrbasisjoinlog").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadswrbasisjoinlog").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader)
                    tmpStringReader.Close()
                End If

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

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Sub
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Sub
        End Try

        Cursor.Current = Cursors.Default

    End Sub

#End Region

#Region "料批卡控"

    Private Sub funLoadAllMaterialLot()

        Dim drAdd As DataRow
        Dim drSel As DataRow()
        Dim defNullDate As Date = CDate("9999/12/31")          '製造日期或保存期限為Null時, 填入9999/12/31, 以防步Null錯誤, 因Null表示不受管控, 可以較後使用, 故填入較大的值

        dtAllMTLLot = New DataTable("AllMTLLot")
        dtAllMTLLot.Columns.Add("MaterialNo", System.Type.GetType("System.String"))         '主料號
        dtAllMTLLot.Columns.Add("MaterialLotNo", System.Type.GetType("System.String"))
        dtAllMTLLot.Columns.Add("Qty", System.Type.GetType("System.Decimal"))
        dtAllMTLLot.Columns.Add("MFGDate", System.Type.GetType("System.DateTime"))
        dtAllMTLLot.Columns.Add("ExpireDate", System.Type.GetType("System.DateTime"))
        dtAllMTLLot.Columns.Add("InputDate", System.Type.GetType("System.DateTime"))

        dtAllMTLLot.Columns.Add("SubstituteMaterialNo", System.Type.GetType("System.String"))    '新增一替代料欄位,2010/03/26,by yumei, 實際用料的料號
        dtAllMTLLot.Columns.Add("SubstituteMaterialLevel", System.Type.GetType("System.Int16"))  '新增一替代料位階欄位,2013/01/08,by Kevin
        dtAllMTLLot.Columns.Add("SubstituteMaterialType", System.Type.GetType("System.String"))  '新增一替代料類型欄位,2013/01/08,by Kevin
        dtAllMTLLot.Columns.Add("SubstituteStdQty", System.Type.GetType("System.Decimal"))       '新增一替代料標準用量欄位,2013/01/08,by Kevin
        dtAllMTLLot.Columns.Add("CheckLotNo", System.Type.GetType("System.Int16"))               '新增一替代料是否檢查批號欄位,2013/01/08,by Kevin

        dtAllMTLLot.Columns.Add("SeqNo", System.Type.GetType("System.Int16"))           '記錄同料號間各料批應被使用的次序

        Select Case dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString

            Case "0"          ' 發料點(線邊倉或工單)
                '將Temp_Material中各主料所有可用料批全數取出, 存入dtAllMTLLot中
                For Each drMTL As DataRow In dsWIP.Tables(tblTMaterial).Rows
                    Call funLoadSubstituteMaterial_Main(drMTL("MaterialNo"), drMTL("UnitNo"))
                    For Each drMTLLot As DataRow In dsWIP.Tables(tblSubstituteMaterial).Rows
                        drAdd = dtAllMTLLot.NewRow
                        drAdd("MaterialNo") = drMTL("MaterialNo")           'BOM的主料號
                        drAdd("MaterialLotNo") = drMTLLot("MaterialLotNo")
                        drAdd("Qty") = drMTLLot("Qty")
                        If drMTLLot("ManufactureDate").ToString = "" Then
                            drAdd("MFGDate") = defNullDate
                        Else
                            drAdd("MFGDate") = drMTLLot("ManufactureDate")
                        End If
                        If drMTLLot("ExpireDate").ToString = "" Then
                            drAdd("ExpireDate") = defNullDate
                        Else
                            drAdd("ExpireDate") = drMTLLot("ExpireDate")
                        End If
                        If drMTLLot("InputDate").ToString = "" Then
                            drAdd("InputDate") = defNullDate
                        Else
                            drAdd("InputDate") = drMTLLot("InputDate")
                        End If

                        drAdd("SubstituteMaterialNo") = drMTLLot("MaterialNo")          '實際料號, 有可能與主料號同也有可能是替代料號
                        drAdd("SubstituteMaterialLevel") = drMTLLot("SubstituteMaterialLevel")
                        drAdd("SubstituteMaterialType") = drMTLLot("SubstituteMaterialType")
                        drAdd("SubstituteStdQty") = drMTLLot("SubstituteStdQty")
                        drAdd("CheckLotNo") = drMTLLot("CheckLotNo")
                        dtAllMTLLot.Rows.Add(drAdd)
                    Next
                Next

                '計算同一料號各料批的使用次序
                Dim dvAllMTLLot, dvTemp As DataView
                Dim dtTemp As DataTable
                For Each drMTL As DataRow In dsWIP.Tables(tblTMaterial).Rows
                    dvAllMTLLot = New DataView(dtAllMTLLot)
                    dvAllMTLLot.RowFilter = "MaterialNo = '" & drMTL("MaterialNo") & "'"
                    dtTemp = dvAllMTLLot.ToTable(True, {"MFGDate", "ExpireDate", "InputDate"})          '對製造日期,有效日期,入庫日做Distinct篩選
                    dvTemp = dtTemp.DefaultView
                    dvTemp.Sort = "MFGDate, ExpireDate, InputDate"
                    '當MFGDate, ExpireDate, InputDate皆相同時, 需給予相同的SeqNo, 故以Distinct的三個日期下去跑Loop
                    For idx As Integer = 0 To dvTemp.Count - 1
                        drSel = dtAllMTLLot.Select("MaterialNo = '" & drMTL("MaterialNo") & "'" &
                                                   "And MFGDate = #" & Format(dvTemp(idx)("MFGDate"), "yyyy/MM/dd HH:mm:ss") & "#" &
                                                   " And ExpireDate = #" & Format(dvTemp(idx)("ExpireDate"), "yyyy/MM/dd HH:mm:ss") & "#" &
                                                   " And InputDate = #" & Format(dvTemp(idx)("InputDate"), "yyyy/MM/dd HH:mm:ss") & "#")
                        For j As Integer = 0 To drSel.Length - 1
                            drSel(j)("SeqNo") = idx + 1
                        Next
                    Next
                Next

            Case "1"          '設備 已在LoadTemp_Material中處理


        End Select

    End Sub

    Private Sub funAutoSetMaterialLot()

        Dim drSel, dtSelMTL As DataRow()
        Dim decLeftQty As Decimal

        Call funLoadAllMaterialLot()
        Call funLoadTemp_MaterialLot()

        Select Case dsWIP.Tables(tblLotState).Rows(0)("MaterialOption").ToString

            Case "0"          ' 發料點(線邊倉或工單)
                '依據CI刷入的料批先進先出安排用量
                For Each drMTL As DataRow In dsWIP.Tables(tblTMaterial).Rows

                    decLeftQty = drMTL("StdUseQty")

                    drSel = dsWIP.Tables(tblTMaterialLot).Select("MainMaterialNo = '" & drMTL("MaterialNo") & "'", "MFGDate, ExpireDate, InputDate")
                    For idx As Integer = 0 To drSel.Length - 1
                        drAdd = dtMLot.NewRow
                        drAdd("EquipmentNo") = "N/A"
                        drAdd("MaterialNo") = drMTL("MaterialNo")
                        drAdd("MaterialLotNo") = drSel(idx)("MaterialLotNo")
                        drAdd("Qty") = drSel(idx)("Qty")
                        drAdd("SubstituteMaterialNo") = drSel(idx)("MaterialNo")
                        drAdd("SubstituteMaterialLevel") = drSel(idx)("SubstituteMaterialLevel")
                        drAdd("SubstituteMaterialType") = drSel(idx)("SubstituteMaterialType")
                        drAdd("SubstituteStdQty") = drSel(idx)("SubstituteStdQty")
                        drAdd("CheckLotNo") = drSel(idx)("CheckLotNo")

                        ' 計算使用量
                        If (drSel(idx)("Qty") > decLeftQty) Then
                            drAdd("UseQty") = decLeftQty
                            decLeftQty = 0
                        Else
                            drAdd("UseQty") = drSel(idx)("Qty")
                            decLeftQty = decLeftQty - drSel(idx)("Qty")
                        End If

                        dtMLot.Rows.Add(drAdd)
                    Next

                    If (decLeftQty <> 0) Then
                        drMTL("UseQty") = Format(drMTL("StdUseQty") - decLeftQty, "0.########")
                    Else
                        drMTL("UseQty") = Format(drMTL("StdUseQty"), "0.########")
                    End If
                Next

        End Select

    End Sub
    Private Sub LoadMaterialGumType(ByVal MaterialNo As String, ByVal MaterialType As String)
        Dim tmpStringReader As System.IO.StringReader '將字串轉換成可讀入DataSet的物件

        Dim XmlData As String '儲存取回之資料
        Dim XmlSchema As String '儲存取回之資料結構

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

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("materialtype", "MaterialType", "String", CInput(MaterialType), "")
        strParameter &= CombineXMLParameter("materialno", "MaterialNo", "String", CInput(MaterialNo), "")
        strParameter &= CombineXMLParameter("issuestate", "IssueState", "Integer", defInteger, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsMTL.LoadMaterialGumType", InXml)

            '利用XmlDoc物件處理ReturnValue 
            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)

            If Not ChkExecutionSuccess(XmlDoc) Then
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If

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

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

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

            '當物料類別及物料編號都有設時，判斷時先依據有設MATERIALNO的判斷(非*)
            If dsDefine.Tables(strTableName).Rows.Count > 1 Then
                For index = 0 To dsDefine.Tables(strTableName).Rows.Count - 1
                    Dim dr As DataRow = dsDefine.Tables(strTableName).Rows(index)
                    If dr("MaterialNo").ToString = "*" Then
                        dr.Delete()
                        Exit For
                    End If
                Next
                dsDefine.Tables(strTableName).AcceptChanges()
            End If

        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub
    Private Sub funLoadWipInventory_Raw(ByVal MaterialNo As String, ByVal MaterialLotNo As String)

        Dim tmpStringReader As System.IO.StringReader '將字串轉換成可讀入DataSet的物件
        Dim XmlData As String '儲存取回之資料
        Dim XmlSchema As String '儲存取回之資料結構

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

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("materialno", "MaterialNo", "String", CInput(MaterialNo), "")
        strParameter = CombineXMLParameter("materiallotno", "MaterialLotNo", "String", CInput(MaterialLotNo), "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsINV.LoadWIPInventory_Raw", InXml)

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

                strRaw = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadwipinventory_raw").Item(0).SelectNodes("name").Item(0).InnerXml
                '取出Schema,dataset讀取Schema可防止Null Field及DateTime的問題
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadwipinventory_raw").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsINV.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                '取出Data
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadwipinventory_raw").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsINV.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Sub
            End If

        Catch ex As Exception
            'MsgBox("Unexpected Error. Load Raw of WIP Inventory failed," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)

        Finally
            tmpStringReader = Nothing

        End Try

    End Sub
#End Region

#Region "聯產品"

    Private Sub btnGetProduct_Click(sender As Object, e As EventArgs) Handles btnGetProduct.Click

        Dim drSel As DataRow()
        Dim strUniPrdPara As String

        '讀取系統參數AllowLotProductChange(允許生產批變更產品) 要從MES或ERP去撈聯產品資訊
        drSel = dsWIP.Tables(tblSYSParameter).Select("ParameterNo = 'AllowLotProductChange'")
        If drSel.Length > 0 Then
            strUniPrdPara = drSel(0)("ParameterValue").ToString
        End If

        Select Case strUniPrdPara
            Case "0" '不允許
                btnGetProduct.Enabled = False
            Case "1" '撈MES產品資訊

                Call funLoadProduct()

                Cursor.Current = Cursors.WaitCursor

                If dsWIP.Tables(tblProductBasis) Is Nothing Then Exit Sub

                If dsWIP.Tables(tblProductBasis).DefaultView.Count = 0 Then
                    iMESExceptionManager.ExceptionManager.iMESMsgBoxShowDialog(ChgTranslateName_Msg("0000-103021", "[%Product Basis%]"), MsgBoxStyle.Exclamation, Me.Text)
                    Exit Sub
                End If

                Dim fSearch As New frmCOMSearch
                fSearch.dvSearch = dsWIP.Tables(tblProductBasis).DefaultView
                fSearch.strFindColumnName = "ProductNo"
                '20221214,13871,右鍵 儲存設計 需要使用Owner(程式碼由程序建立)
                fSearch.ShowDialog(Me)
                fSearch.Dispose()

                If drSearch Is Nothing Then Exit Sub

                If txtUnionProductNo.Text <> drSearch("ProductNo").ToString Then
                    txtUnionProductNo.Text = drSearch("ProductNo").ToString
                End If
                If txtUnionProductVersion.Text <> drSearch("ProductVersion").ToString Then
                    txtUnionProductVersion.Text = drSearch("ProductVersion").ToString
                End If
                If txtUnionProductUnit.Text <> drSearch("UnitNo").ToString Then
                    txtUnionProductUnit.Text = drSearch("UnitNo").ToString
                End If

                '選取聯產品資訊時, 需自動勾起聯產品checkBox
                chkUnionProductNo.Checked = True

                Cursor.Current = Cursors.Default

            Case "2" '撈ERP TIPTOP 聯產品資訊

                Call funCombineTTInXml(dsWIP.Tables(tblOEMOBasis).Rows(0)("ProductNo").ToString)

            Case "3" '撈ERP T100 聨產品資訊

                Call funCombineT100InXml(dsWIP.Tables(tblOEMOBasis).Rows(0)("ProductNo").ToString, dsWIP.Tables(tblOEMOBasis).Rows(0)("MONO").ToString)

            Case "4" '撈E10ICD 聨產品資訊
                '87580: [605]iMES與E10整合_第一階段_SDD210205_01-09取得E10聯產品資料
                Call funCombineE10ICDInXml(dsWIP.Tables(tblOEMOBasis).Rows(0)("ProductNo").ToString, dsWIP.Tables(tblOEMOBasis).Rows(0)("MONO").ToString)

            Case "5" '撈ERP TIPTOPICD 聨產品資訊

                Call funCombineTTICDInXml(dsWIP.Tables(tblOEMOBasis).Rows(0)("ProductNo").ToString)

        End Select

    End Sub

    Private Sub chkUnionProductNo_CheckedChanged(sender As Object, e As EventArgs) Handles chkUnionProductNo.CheckedChanged
        '取消勾選聯產品時需將聯產品資訊清空
        If Not chkUnionProductNo.Checked Then
            txtUnionProductNo.Text = ""
            txtUnionProductVersion.Text = ""
            txtUnionProductUnit.Text = ""
        End If
    End Sub

    Private Function funChkLastBR(ByVal LinkName As String) As Boolean

        funChkLastBR = False        '預設為false

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", CInput(LotNo), "")
        strParameter += CombineXMLParameter("linkname", "LinkName", "String", LinkName, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.ChkLastBR", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '取出ShiftNo
                If XmlDoc.GetElementsByTagName("lastbr").Item(0).SelectNodes("value").Count > 0 Then
                    funChkLastBR = CBool(XmlDoc.DocumentElement.GetElementsByTagName("lastbr").Item(0).SelectNodes("value").Item(0).InnerText)
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

    End Function

#End Region

#Region "Bin Process"

    Private Sub funLoadSystemBin()

        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        InXml = CombineXMLRequest(strIdentity, "")

        Try
            ' 2016 YF, Dim wsSYS As New wsSYS.wsSYS
            Dim XmlDoc As New XmlDocument
            ' 2016 YF, wsSYS.Url = LocalizeWebService(wsSYS.Url.ToString)
            ' 2016 YF, wsSYS.EnableDecompression = True
            ' 2016 YF, OutXml = wsSYS.LoadBin(InXml)
            OutXml = InvokeSrv("wsSYS.LoadBin", InXml)

            ' 2016 YF, wsSYS.Dispose()

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

                If Not dsWIP.Tables(strSysBin) Is Nothing Then
                    dvSysBin = dsWIP.Tables(strSysBin).DefaultView

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

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
        End Try

    End Sub


    Private Sub funLoadGoodBinState()

        '先判斷DS中是否已有相同名稱的資料表,若有需先remove,否則會有錯誤
        If Not IsNothing(dsWIP.Tables(strBinState)) Then
            dsWIP.Tables.Remove(strBinState)
        End If

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, UserId, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            ' 2016 YF, OutXml = wsWIP.LoadGoodBinState(InXml)
            OutXml = InvokeSrv("wsWIP.LoadGoodBinState", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                strBinState = XmlDoc.GetElementsByTagName("returnvalue").Item(0).SelectNodes("loadgoodbinstate").Item(0).SelectNodes("name").Item(0).InnerXml
                XmlSchema = XmlDoc.DocumentElement.GetElementsByTagName("loadgoodbinstate").Item(0).SelectNodes("schema").Item(0).InnerXml
                If XmlSchema <> "" Then
                    '將XML讀入String Reader object中,因為Dataset讀入XML時必須透過String Reader物件
                    tmpStringReader = New System.IO.StringReader(XmlSchema)
                    dsWIP.ReadXmlSchema(tmpStringReader)
                    tmpStringReader.Close()
                End If
                XmlData = XmlDoc.DocumentElement.GetElementsByTagName("loadgoodbinstate").Item(0).SelectNodes("value").Item(0).InnerXml
                If XmlData <> "" Then
                    tmpStringReader = New System.IO.StringReader(XmlData)
                    dsWIP.ReadXml(tmpStringReader, XmlReadMode.InferSchema)
                    tmpStringReader.Close()
                End If
                iGoodBinStateQty = 0
                If dsWIP.Tables(strBinState).Rows.Count > 0 Then
                    For Each drTemp As DataRow In dsWIP.Tables(strSysBin).Rows
                        iGoodBinStateQty += CInt(dsWIP.Tables(strBinState).Rows(0)(drTemp("BinNo").ToString))
                    Next
                End If

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

        Catch ex As Exception
            'MsgBox("Unexpected Error. Load Good Bin State of LotNo:" & LotNo & " Failed," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)

        Finally

        End Try

    End Sub

#End Region

    Private Function funGetLotStateIncludeData() As Integer

        funGetLotStateIncludeData = -1

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, Now)
        strParameter = CombineXMLParameter("lotno", "LotNo", "String", LotNo, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            OutXml = InvokeSrv("wsWIP.GetLotStateIncludeData", InXml)

            Dim XmlDoc As New XmlDocument
            XmlDoc.LoadXml(OutXml)
            If ChkExecutionSuccess(XmlDoc) Then
                '取出ShiftNo
                If XmlDoc.GetElementsByTagName("havecomponent").Item(0).SelectNodes("value").Count > 0 Then
                    HaveComponent = XmlDoc.DocumentElement.GetElementsByTagName("havecomponent").Item(0).SelectNodes("value").Item(0).InnerText
                End If
                If XmlDoc.GetElementsByTagName("havelevel").Item(0).SelectNodes("value").Count > 0 Then
                    HaveLevel = XmlDoc.DocumentElement.GetElementsByTagName("havelevel").Item(0).SelectNodes("value").Item(0).InnerText
                End If
            Else
                ExceptionManager.iMESShowDialog(GetExceptionCode(XmlDoc), GetExceptionSysMsg(XmlDoc), GetExceptionStack(XmlDoc))
                Exit Function
            End If

            XmlDoc = Nothing

        Catch ex As iMESException.MESException
            ExceptionManager.iMESShowDialog(ex.ErrorCode, ex.Message, ex.StackTrace)
            Exit Function
        Catch ex As Exception
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)
            Exit Function
        End Try

        funGetLotStateIncludeData = 0

    End Function


#Region "自動計算GoodQty、LossQty的數量"
    Private Sub iugKeyIn_iMESUltraGrid_AfterCellActivate(sender As Object, e As EventArgs) Handles iugKeyIn.iMESUltraGrid_AfterCellActivate

        If funGetParameter("SysInfo", "CalculateQty") = 1 Then
            Dim drSelError() As DataRow
            Dim decScrapQty As Decimal = 0
            Dim decLossQty As Decimal = 0
            drSelError = dtKeyIn.Select("AttribNo = 'LossQty'")
            If drSelError.Length <> 0 Then
                If IsNumeric(drSelError(0)("AttribValue")) Then
                    decLossQty = drSelError(0)("AttribValue")
                End If
            End If
            drSelError = dsWIP.Tables(tblOPError).Select("ReasonType=0 And CheckFlag=" & True)
            For i As Integer = 0 To drSelError.Length - 1
                decScrapQty = decScrapQty + drSelError(i)("ErrorQty")
            Next
            drSelError = dtKeyIn.Select("AttribNo = 'ScrapQty'")
            If drSelError.Length <> 0 Then
                drSelError(0)("AttribValue") = decScrapQty
            End If
            drSelError = dtKeyIn.Select("AttribNo = 'GoodQty'")
            Dim blnCalulate As Boolean = True '0111211: [49-1]扫脚_check-out_bin分布调整,若有bin分佈調整, 則不自動計算GoodQty 
            If drSelError.Length <> 0 Then
                If HaveLevel AndAlso iGoodBinStateQty <> 0 Then
                    If Not IsNothing(dtBinNew) AndAlso dtBinNew.Rows.Count > 0 Then
                        blnCalulate = False
                    End If
                End If
                If blnCalulate Then
                    drSelError(0)("AttribValue") = CDec(txtCurQty.Text) - decScrapQty - decLossQty
                End If
            End If
        End If

    End Sub
#End Region


    Private Sub uegMaterial_KeyIn2_ExpandedStateChanged(sender As Object, e As EventArgs) Handles uegMaterial_KeyIn2.ExpandedStateChanged, uegAttrib_Equipment.ExpandedStateChanged

        If uegMaterial_KeyIn2.Expanded Then

            If uegAttrib_Equipment.Expanded Then
                uegMaterial_KeyIn2.Size = New System.Drawing.Size(uegMaterial_KeyIn2.Width, ((uplAll.Height - uegLotInfo.Height) / 3) * 2 - 10)
                uegAttrib_Equipment.Size = New System.Drawing.Size(uegAttrib_Equipment.Width, ((uplAll.Height - uegLotInfo.Height) / 3) - 10)
            End If

        Else

            If uegAttrib_Equipment.Expanded Then
                uegAttrib_Equipment.Size = New System.Drawing.Size(uegAttrib_Equipment.Width, uplAll.Height - uegLotInfo.Height - 20)
            End If

        End If

    End Sub
#Region "'//^_^ADD BY  H-14278 2023-12-29 新设备上料"
    Private Sub funLoadMOMaterialList(ByVal MONo As String, ByVal OPNo As String) '//取出MO MaterialList資料

        If Not IsNothing(dsOE.Tables(strMOList)) Then         '修正用料清單多次查詢重複計算問題
            dsOE.Tables.Remove(strMOList)
        End If

        '組InXml的字串
        strIdentity = CombineXMLIdentity(gComputerName, gUserNo, GetNow())
        strParameter = CombineXMLParameter("mono", "MONo", "String", MONo.ToUpper, "")
        strParameter += CombineXMLParameter("opno", "OPNo", "String", OPNo.ToUpper, "")
        InXml = CombineXMLRequest(strIdentity, strParameter)

        Try
            ' 2016 YF, OutXml = wsOE.LoadMOMaterialListJoinMOBasis(InXml)
            OutXml = InvokeSrv("wsOE.LoadMOMaterialListJoinMOBasis", InXml)

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

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

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

        Catch ex As Exception
            'MsgBox("Unexpected Error. Load MO Material List Failed," & e1.Message, MsgBoxStyle.Exclamation)
            ExceptionManager.iMESShowDialog(defWinErrCode, ex.Message, ex.StackTrace)

        Finally
            tmpStringReader = Nothing
        End Try

    End Sub

#End Region

End Class

