Esempio n. 1
0
        /// <summary>
        /// 檢查站口訊號是否正確-站對站
        /// </summary>
        private void funStnToStnCheck(string StnNo, string NewStnNo)
        {
            string strStnNo = string.Empty;
            string strSQL   = string.Empty;
            string strEM    = string.Empty;

            DataTable            objDataTable   = new DataTable();
            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.None);

            try
            {
                strSQL = "SELECT * FROM StnDef WHERE StnNo IN ('" + StnNo + "','" + NewStnNo + "') ORDER BY ";
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (objDataTable != null)
                {
                    objDataTable.Clear();
                    objDataTable.Dispose();
                    objDataTable = null;
                }
                if (SystemTraceLog != null)
                {
                    SystemTraceLog = null;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新 PLC 或 DB 連線狀態
        /// </summary>
        /// <param name="Connect"></param>
        /// <param name="lblConnect"></param>
        private void funShowConnect(bool Connect, ref Label lblConnect)
        {
            bool bolLastConnect = lblConnect.Text == "已連線";
            bool bolFlag        = lblConnect.Text == "None";

            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);

            switch (Connect)
            {
            case true:
                lblConnect.Text      = "已連線";
                lblConnect.BackColor = Color.Lime;

                //if(!bolLastConnect || bolFlag)
                //{
                //    SystemTraceLog.LogMessage =
                //        lblConnect.Name.Contains("DB") ? "Connection DB Success!" : "Connection " + lblConnect.Name.Substring(3, 5) + " Success!";
                //    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                //}
                break;

            case false:
            default:
                lblConnect.Text      = "未連線";
                lblConnect.BackColor = Color.Red;

                //if(bolLastConnect || bolFlag)
                //{
                //    SystemTraceLog.LogMessage =
                //        lblConnect.Name.Contains("DB") ? "Connection DB Fail!" : "Connection " + lblConnect.Name.Substring(3, 5) + " Fail!";
                //    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                //}
                break;
            }
        }
Esempio n. 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string strSQL    = string.Empty;
            string strEM     = string.Empty;
            string strCmdSno = string.Empty;

            try
            {
                strCmdSno = dgvCmdList.SelectedRows[0].Cells["Command"].Value.ToString();
                strSQL    = "UPDATE EQUCMD SET RENEWFLAG='F' WHERE CMDSNO='" + strCmdSno + "'";
                if (MessageBox.Show("Delete Crane CmdSno:<" + strCmdSno + "> ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            SystemTraceLog.LogMessage = "User Delete Equ Cmd!";
                            SystemTraceLog.LeftCmdSno = strCmdSno;
                            ShowSystemTrace(this, SystemTraceLog);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
        }
        /// <summary>
        /// 寫入PC To PLC HandShaking
        /// </summary>
        /// <param name="HandShake_Address">交握訊號位置</param>
        /// <param name="SetData">寫入PLC資料</param>
        /// <returns></returns>
        private void funWritePC2PLC_HandShake(string str, int iPLCNo)
        {
            string strAddress = string.Empty;

            //if(funGetWritePC2PLCAddress("System", ref strAddress))
            //{
            //    if(!clsSystem.gobjPLC.funWritePLC(strAddress, str))
            //    {
            //        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
            //        SystemTraceLog.LogMessage = "Write PLC HandShaking Fail!";
            //        SystemTraceLog.BufferName = "System";
            //        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
            //    }
            //}
            switch (iPLCNo)
            {
            case 1:

                if (!clsSystem.gobjPLC.funWritePLC("D3000", str))
                {
                    clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                    SystemTraceLog.LogMessage = "Write PLC1 HandShaking Fail!";
                    SystemTraceLog.BufferName = "System";
                    funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                    SystemTraceLog = null;
                }
                break;

            case 2:
                if (!clsSystem.gobjPLC2.funWritePLC("D100", str))
                {
                    clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                    SystemTraceLog.LogMessage = "Write PLC2 HandShaking Fail!";
                    SystemTraceLog.BufferName = "System";
                    funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                    SystemTraceLog = null;
                }
                break;

            case 3:
                if (!clsSystem.gobjPLC3.funWritePLC("D100", str))
                {
                    clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                    SystemTraceLog.LogMessage = "Write PLC3 HandShaking Fail!";
                    SystemTraceLog.BufferName = "System";
                    funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                    SystemTraceLog = null;
                }
                break;
            }
        }
        /// <summary>
        /// 寫入PLC時間
        /// </summary>
        /// <returns></returns>
        private void funWritePLCSetDateTime(int iPLCNo)
        {
            string strYear    = DateTime.Now.ToString("yy");
            string strMon     = DateTime.Now.ToString("MM");
            string strDay     = DateTime.Now.ToString("dd");
            string strHour    = DateTime.Now.ToString("HH");
            string strMin     = DateTime.Now.ToString("mm");
            string strAddress = string.Empty;

            if (funGetWritePC2PLCAddress("System", clsPLC.enuAddressSection.DataTime, ref strAddress))
            {
                switch (iPLCNo)
                {
                case 1:
                    if (!clsSystem.gobjPLC.funWritePLC(strAddress, strYear, strMon, strDay, strHour, strMin))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC1 DateTime Fail!";
                        SystemTraceLog.BufferName = "System";
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                    break;

                case 2:
                    if (!clsSystem.gobjPLC2.funWritePLC(strAddress, strYear, strMon, strDay, strHour, strMin))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC2 DateTime Fail!";
                        SystemTraceLog.BufferName = "System";
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                    break;

                case 3:
                    if (!clsSystem.gobjPLC3.funWritePLC(strAddress, strYear, strMon, strDay, strHour, strMin))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC3 DateTime Fail!";
                        SystemTraceLog.BufferName = "System";
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                    break;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 取得 Crane Mode 並更新
        /// </summary>
        private void funReadCraneMode()
        {
            string    strSQL       = "SELECT * FROM EQUMODELOG WHERE ENDDT IN ('',' ')";
            string    strEM        = string.Empty;
            DataTable objDataTable = new DataTable();

            try
            {
                if (clsSystem.gobjDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                {
                    for (int intCount = 0; intCount < objDataTable.Rows.Count; intCount++)
                    {
                        if (tlpCraneSts.Controls.ContainsKey("lblCrane" + objDataTable.Rows[intCount]["EQUNO"].ToString() + "Mode"))
                        {
                            Label  objLabel            = (Label)tlpCraneSts.Controls["lblCrane" + objDataTable.Rows[intCount]["EQUNO"].ToString() + "Mode"];
                            string strCurrentCraneMode = objDataTable.Rows[intCount]["EQUMODE"].ToString();
                            string strLastCraneMode    = objLabel.Text.Substring(0, 1);
                            string strCraneNo          = objDataTable.Rows[intCount]["EQUNO"].ToString();

                            if (strLastCraneMode != strCurrentCraneMode)
                            {
                                funShowCraneMode(strCurrentCraneMode, ref objLabel);
                                clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                                SystemTraceLog.LogMessage    = "Crane " + strCraneNo + " Mode Change";
                                SystemTraceLog.CraneNo       = strCraneNo;
                                SystemTraceLog.CraneMode     = strCurrentCraneMode;
                                SystemTraceLog.CraneModeLast = strLastCraneMode;
                                funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (objDataTable != null)
                {
                    objDataTable.Clear();
                    objDataTable.Dispose();
                    objDataTable = null;
                }
            }
        }
 /// <summary>
 /// 取得 PC->PLC 寫入位置
 /// </summary>
 /// <param name="BufferName">PLC位置</param>
 /// <returns></returns>
 private bool funGetWritePC2PLCAddress(string BufferName, ref string Address)
 {
     if (clsSystem.gdicPC2PLCMap.ContainsKey(BufferName))
     {
         Address = "D" + clsSystem.gdicPC2PLCMap[BufferName].ToString();
         return(true);
     }
     else
     {
         Address = string.Empty;
         clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
         SystemTraceLog.LogMessage = "Get Write PLC Address Fail!";
         SystemTraceLog.BufferName = BufferName;
         funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
         SystemTraceLog = null;
         return(false);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 移除已完成Equ Cmd
        /// </summary>
        /// <param name="strCmdSno"></param>
        private void funDeleteEquCmd(string strCmdSno)
        {
            string strSQL = string.Empty;
            string strEM  = string.Empty;
            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.None);

            try
            {
                strSQL = "UPDATE EQUCMD SET RENEWFLAG='F' WHERE CMDSTS='9' AND RENEWFLAG='Y' AND CMDSNO='" + strCmdSno + "'";
                if (clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                {
                    SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                    SystemTraceLog.LogMessage = "Delete Equ Cmd Success!";
                    SystemTraceLog.LeftCmdSno = strCmdSno;
                    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                }
                else
                {
                    SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                    SystemTraceLog.LogMessage = "Delete Equ Cmd Fail!";
                    SystemTraceLog.LeftCmdSno = strCmdSno;
                    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                }

                strSQL  = "UPDATE EQUCMD SET RENEWFLAG='F' WHERE CMDSTS='9' AND RENEWFLAG='Y'";
                strSQL += " AND CMDSNO NOT IN (SELECT CMD_SNO FROM CMD_MST WHERE CMD_STS < '7')";
                clsSystem.gobjDB.funExecSql(strSQL, ref strEM);
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (SystemTraceLog != null)
                {
                    SystemTraceLog = null;
                }
            }
        }
 /// <summary>
 /// 取得PLC特定寫入位置
 /// </summary>
 /// <param name="BufferName">PLC位置</param>
 /// <param name="Section">特定位置</param>
 /// <returns></returns>
 private bool funGetWritePC2PLCAddress(string BufferName, clsPLC.enuAddressSection Section, ref string Address)
 {
     if (clsSystem.gdicPC2PLCMap.ContainsKey(BufferName))
     {
         Address = "D" + (clsSystem.gdicPC2PLCMap[BufferName] + (int)Section).ToString();
         return(true);
     }
     else
     {
         if (ShowSystemTrace != null)
         {
             clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
             SystemTraceLog.LogMessage     = "User Get Write PLC Address Fail!";
             SystemTraceLog.BufferName     = BufferName;
             SystemTraceLog.AddressSection = Section.ToString();
             ShowSystemTrace(this, SystemTraceLog);
             SystemTraceLog = null;
         }
         return(false);
     }
 }
Esempio n. 10
0
        private void funNewCmdForPickup(string strCmdSno)
        {
            string strSql = string.Empty;
            string strEM  = string.Empty;
            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.None);

            try
            {
                //須確認Update CMd_MST 時不影響過帳
                strSql = "Update ";
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (SystemTraceLog != null)
                {
                    SystemTraceLog = null;
                }
            }
        }
        /// <summary>
        /// 從特定位置寫入PLC
        /// </summary>
        /// <param name="BufferName"></param>
        /// <param name="Section"></param>
        /// <param name="PLCValues"></param>
        /// <returns></returns>
        private bool funWritePC2PLCSingel(string BufferName, clsPLC.enuAddressSection Section, params string[] PLCValues)
        {
            string strAddress = string.Empty;

            if (funGetWritePC2PLCAddress(BufferName, Section, ref strAddress))
            {
                if (BufferName.Substring(0, 1) == "C" || BufferName.Substring(0, 1) == "D" || BufferName.Substring(0, 1) == "E")
                {
                    if (clsSystem.gobjPLC2.funWritePLC(strAddress, PLCValues))
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                            SystemTraceLog.LogMessage     = "User Write PLC Success!";
                            SystemTraceLog.BufferName     = BufferName;
                            SystemTraceLog.AddressSection = Section.ToString();
                            SystemTraceLog.PLCValues      = PLCValues;
                            ShowSystemTrace(this, SystemTraceLog);
                            SystemTraceLog = null;
                        }
                        return(true);
                    }
                    else
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                            SystemTraceLog.LogMessage     = "Write PLC Fail!";
                            SystemTraceLog.BufferName     = BufferName;
                            SystemTraceLog.AddressSection = Section.ToString();
                            SystemTraceLog.PLCValues      = PLCValues;
                            ShowSystemTrace(this, SystemTraceLog);
                            SystemTraceLog = null;
                        }
                        return(false);
                    }
                }
                else if (BufferName.Substring(0, 1) == "F" || BufferName.Substring(0, 1) == "G")
                {
                    if (clsSystem.gobjPLC3.funWritePLC(strAddress, PLCValues))
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                            SystemTraceLog.LogMessage     = "User Write PLC Success!";
                            SystemTraceLog.BufferName     = BufferName;
                            SystemTraceLog.AddressSection = Section.ToString();
                            SystemTraceLog.PLCValues      = PLCValues;
                            ShowSystemTrace(this, SystemTraceLog);
                            SystemTraceLog = null;
                        }
                        return(true);
                    }
                    else
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                            SystemTraceLog.LogMessage     = "Write PLC Fail!";
                            SystemTraceLog.BufferName     = BufferName;
                            SystemTraceLog.AddressSection = Section.ToString();
                            SystemTraceLog.PLCValues      = PLCValues;
                            ShowSystemTrace(this, SystemTraceLog);
                            SystemTraceLog = null;
                        }
                        return(false);
                    }
                }
                else
                {
                    if (clsSystem.gobjPLC.funWritePLC(strAddress, PLCValues))
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                            SystemTraceLog.LogMessage     = "User Write PLC Success!";
                            SystemTraceLog.BufferName     = BufferName;
                            SystemTraceLog.AddressSection = Section.ToString();
                            SystemTraceLog.PLCValues      = PLCValues;
                            ShowSystemTrace(this, SystemTraceLog);
                            SystemTraceLog = null;
                        }
                        return(true);
                    }
                    else
                    {
                        if (ShowSystemTrace != null)
                        {
                            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                            SystemTraceLog.LogMessage     = "Write PLC Fail!";
                            SystemTraceLog.BufferName     = BufferName;
                            SystemTraceLog.AddressSection = Section.ToString();
                            SystemTraceLog.PLCValues      = PLCValues;
                            ShowSystemTrace(this, SystemTraceLog);
                            SystemTraceLog = null;
                        }
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 清除 PC->PLC 的PLC Singel
        /// </summary>
        /// <param name="BufferName"></param>
        private void funRefreshPC2PLCSingel(string BufferName)
        {
            string strAddress = string.Empty;

            if (funGetWritePC2PLCAddress(BufferName, ref strAddress))
            {
                string[] strarrValues = new string[] { "0", "0", "0", "0", "0" };
                if (BufferName.Substring(0, 1) == "A" || BufferName.Substring(0, 1) == "B")
                {
                    if (clsSystem.gobjPLC.funWritePLC(strAddress, strarrValues))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Refresh PLC Success!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = strarrValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Refresh PLC Fail!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = strarrValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                }
                if (BufferName.Substring(0, 1) == "C" || BufferName.Substring(0, 1) == "D" || BufferName.Substring(0, 1) == "E")
                {
                    if (clsSystem.gobjPLC2.funWritePLC(strAddress, strarrValues))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Refresh PLC Success!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = strarrValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Refresh PLC Fail!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = strarrValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                }
                else
                {
                    if (clsSystem.gobjPLC3.funWritePLC(strAddress, strarrValues))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Refresh PLC Success!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = strarrValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Refresh PLC Fail!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = strarrValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                    }
                }

                strarrValues = null;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 寫入Crane命令-站對站
        /// </summary>
        private void funStnToStnEquPLCCmd()
        {
            string strSQL = string.Empty;
            string strEM  = string.Empty;

            DataTable objDataTable = new DataTable();
            Dictionary <string, clsCmdSno> dicCmdSno      = new Dictionary <string, clsCmdSno>();
            clsTraceLogEventArgs           SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);

            try
            {
                strSQL = "SELECT * FROM CMD_MST WHERE Cmd_Sno<>'' and CMD_MODE = '4' AND CMD_STS ='1' AND TRACE ='" + clsTrace.cstrStoreOutTrace_ReleaseEquPLCCmd + "' ORDER BY CMD_SNO,LOC,PRTY,Crt_Date";
                if (clsSystem.gobjDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                {
                    #region 取得命令
                    for (int intCount = 0; intCount < objDataTable.Rows.Count; intCount++)
                    {
                        if (dicCmdSno.ContainsKey(objDataTable.Rows[intCount]["CMD_SNO"].ToString()))
                        {
                            string strCmdSno = objDataTable.Rows[intCount]["CMD_SNO"].ToString();
                            dicCmdSno[strCmdSno].CmdSno  = objDataTable.Rows[intCount]["CMD_SNO"].ToString();
                            dicCmdSno[strCmdSno].Stn_No  = objDataTable.Rows[intCount]["Stn_No"].ToString();
                            dicCmdSno[strCmdSno].NewLoc  = objDataTable.Rows[intCount]["New_Loc"].ToString();
                            dicCmdSno[strCmdSno].CmdMode = 2;
                        }
                        else
                        {
                            clsCmdSno CmdSno = new clsCmdSno();
                            CmdSno.CmdSno   = objDataTable.Rows[intCount]["CMD_SNO"].ToString();
                            CmdSno.Stn_No   = objDataTable.Rows[intCount]["Stn_No"].ToString();
                            CmdSno.NewLoc   = objDataTable.Rows[intCount]["New_Loc"].ToString();
                            CmdSno.Priority = int.Parse(objDataTable.Rows[intCount]["PRTY"].ToString());
                            CmdSno.CmdMode  = 2;
                            dicCmdSno.Add(CmdSno.CmdSno, CmdSno);
                        }
                    }
                    #endregion 取得命令



                    foreach (clsCmdSno CmdSno in dicCmdSno.Values)
                    {
                        if (funStnNo2Crane(CmdSno.Stn_No) != funStnNo2Crane(CmdSno.NewLoc))
                        {
                            continue;
                        }


                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                        SystemTraceLog.LogMessage = "Find Transfer Cmd Success!";
                        SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                        SystemTraceLog.StnNo      = CmdSno.Stn_No;
                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);

                        int intBufferIndex, intBufferIndex_Out;
                        #region 寫入PLC

                        objDataTable = new DataTable();
                        strSQL       = "SELECT * FROM StnDef WHERE StnNo IN ('" + CmdSno.Stn_No + "') ORDER BY STNNO";
                        if (clsSystem.gobjSystemDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                        {
                            intBufferIndex = clsTool.funConvertToInt(objDataTable.Rows[0]["BufferIndex"].ToString());

                            #region 註解
                            //if (objBufferData.PLC2PCBuffer[intBufferIndex].StnModeCode_Load &&
                            //    objBufferData.PLC2PCBuffer[intBufferIndex].ReadNotice == (int)clsPLC2PCBuffer.enuReadNotice.Read &&
                            //    objBufferData.PLC2PCBuffer[intBufferIndex].Ready == (int)clsPLC2PCBuffer.enuReady.InReady &&
                            //    string.IsNullOrWhiteSpace(objBufferData.PLC2PCBuffer[intBufferIndex].LeftCmdSno)
                            //    )
                            //{
                            //    #region 讀取BCR

                            //    objDataTable = new DataTable();
                            //    strSQL = "SELECT * FROM IN_BUF WHERE BCR_NO IN";
                            //    strSQL += " ('" + objBCRData[(intBufferIndex+1)/2, clsBCR.enuBCRLoc.Once].BCRNo + "')";
                            //    if (clsSystem.gobjDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                            //    {
                            //        foreach (DataRow drTmp in objDataTable.Rows)
                            //        {
                            //            switch (drTmp["BCR_STS"].ToString())
                            //            {
                            //                case clsBCRSts.cstrReadFinish:
                            //                    if (drTmp["BCR_No"].ToString() == objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo)
                            //                    {
                            //                        if (objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID != drTmp["BCR_DATA"].ToString())
                            //                        {
                            //                            objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRSts =
                            //                                clsTool.funGetEnumValue<clsBCR.enuBCRSts>(drTmp["BCR_STS"].ToString());
                            //                            objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID = drTmp["BCR_DATA"].ToString();

                            //                            SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //                            SystemTraceLog.LogMessage = "BCR Read Success!";
                            //                            SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;
                            //                            SystemTraceLog.BCRID = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID;
                            //                            SystemTraceLog.StnNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].StnNo;
                            //                            funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);

                            //                        }
                            //                    }
                            //                    break;
                            //                case clsBCRSts.cstrNone:
                            //                    #region 啟動BCR
                            //                    clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin);
                            //                    if (funUpdateBCRSts(clsBCR.enuBCRSts.Reading, objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo, clsReBCRID.cstrBCRDataInit))
                            //                    {
                            //                        objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRSts = clsBCR.enuBCRSts.Reading;
                            //                        objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID = clsReBCRID.cstrBCRDataInit;

                            //                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                            //                        SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //                        SystemTraceLog.LogMessage = "Update Both BCR Sts Success!";
                            //                        SystemTraceLog.BCRSts = ((int)clsBCR.enuBCRSts.Reading).ToString();
                            //                        SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;

                            //                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            //                    }
                            //                    else
                            //                    {
                            //                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                            //                        SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //                        SystemTraceLog.LogMessage = "Update Both BCR Sts Fail!";
                            //                        SystemTraceLog.BCRSts = clsBCR.enuBCRSts.Reading.ToString();
                            //                        SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;
                            //                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            //                    }
                            //                    #endregion 啟動BCR
                            //                    break;

                            //                default:

                            //                    break;
                            //            }
                            //        }
                            //}
                            //    #endregion 讀取BCR

                            //#region 確認BCR讀取是否有誤 For 大立光
                            //if ((objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRSts == clsBCR.enuBCRSts.ReadFinish &&
                            //    objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID == clsReBCRID.cstrBCRError))
                            //{
                            //    clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin);
                            //    if (funUpdateBCRSts(clsBCR.enuBCRSts.None, objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo, clsReBCRID.cstrBCRDataInit))
                            //    {
                            //        if (funWritePC2PLCSingel(
                            //            1,
                            //            objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BufferName,

                            //            clsPLC.enuAddressSection.ReadNotice,
                            //            clsReBCRSts.cstrNG))
                            //        {
                            //            objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRSts = clsBCR.enuBCRSts.None;
                            //            objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID = clsReBCRID.cstrBCRDataInit;

                            //            clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                            //            SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //            SystemTraceLog.LogMessage = "BCR Read Fail!";
                            //            SystemTraceLog.BCRSts = ((int)clsBCR.enuBCRSts.None).ToString();
                            //            SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;
                            //            funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            //        }
                            //        else
                            //            clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                            //    }
                            //    else
                            //    {
                            //        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                            //        SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //        SystemTraceLog.LogMessage = "Update BCR Sts Fail!";
                            //        SystemTraceLog.BCRSts = ((int)clsBCR.enuBCRSts.None).ToString();
                            //        SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;
                            //        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            //    }
                            //}
                            //#endregion 確認讀取是否有誤

                            //#region Update Cmd Trace + 寫入PLC
                            //clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin);
                            //if (funUpdateCmdTrace(CmdSno.CmdSno,
                            //                     objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID,
                            //                     clsCmdSts.cstrCmdSts_Start,
                            //                     clsTrace.cstrStoreInTrace_ReleaseEquPLCCmd,
                            //                     objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo) &&
                            //    funUpdateBCRSts(clsBCR.enuBCRSts.None, objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo, clsReBCRID.cstrBCRDataInit))
                            //{
                            //    if (funWritePC2PLCSingel(
                            //        objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BufferName,
                            //        CmdSno.CmdSno,//序號
                            //        "1", //模式
                            //        "0",//初始通知
                            //        clsFunNotice1.CMD_OK,
                            //        clsFunNotice2.StnInMode,
                            //        clsFunNotice3.None
                            //        ))
                            //    {
                            //        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                            //        SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //        SystemTraceLog.LogMessage = "Stock In Cmd Initiated!";
                            //        SystemTraceLog.CmdSno = CmdSno.CmdSno;
                            //        SystemTraceLog.CmdSts = clsCmdSts.cstrCmdSts_Start;
                            //        SystemTraceLog.Trace = clsTrace.cstrStoreInTrace_ReleaseEquPLCCmd;
                            //        SystemTraceLog.StnNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].StnNo;
                            //        SystemTraceLog.LocID = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID;
                            //        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);

                            //        objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRSts = clsBCR.enuBCRSts.None;
                            //        objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID = clsReBCRID.cstrBCRDataInit;

                            //        SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //        SystemTraceLog.LogMessage = "Update Both BCR Sts Success!";
                            //        SystemTraceLog.BCRSts = ((int)clsBCR.enuBCRSts.None).ToString();
                            //        SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;
                            //        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            //    }
                            //    else
                            //        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                            //}
                            //else
                            //{
                            //    clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                            //    SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //    SystemTraceLog.LogMessage = "UpdateCmd Trace Fail!";
                            //    SystemTraceLog.CmdSno = CmdSno.CmdSno_L;
                            //    SystemTraceLog.CmdSts = clsCmdSts.cstrCmdSts_Start;
                            //    SystemTraceLog.Trace = clsTrace.cstrStoreInTrace_ReleaseEquPLCCmd;
                            //    SystemTraceLog.StnNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].StnNo;
                            //    SystemTraceLog.LocID = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRID;
                            //    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);

                            //    SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                            //    SystemTraceLog.LogMessage = "Update BCR Sts Fail!";
                            //    SystemTraceLog.BCRSts = ((int)clsBCR.enuBCRSts.None).ToString();
                            //    SystemTraceLog.BCRNo = objBCRData[(intBufferIndex + 1) / 2, clsBCR.enuBCRLoc.Once].BCRNo;
                            //    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                            //}
                            //#endregion Update Cmd Trace
                            //}
                            #endregion 註解
                            #endregion 寫入PLC

                            //if (funUpdateCmdTrace(CmdSno.CmdSno, clsCmdSts.cstrCmdSts_Start, clsTrace.cstrStoreOutTrace_ReleaseEquPLCCmd))
                            //{
                            //    //if (funWritePC2PLCSingel(
                            //    //                    StnDef.Buffer,
                            //    //                    CmdSno.CmdSno,
                            //    //                    CmdSno.CmdMode.ToString(),
                            //    //                    CmdSno.IniNotice.ToString()

                            //    //                    ))
                            //}


                            //寫入出庫PLC
                            objDataTable = new DataTable();
                            strSQL       = "SELECT * FROM StnDef WHERE StnNo IN ('" + CmdSno.NewLoc + "') ORDER BY STNNO";
                            if (clsSystem.gobjSystemDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                            {
                                intBufferIndex_Out = clsTool.funConvertToInt(objDataTable.Rows[0]["BufferIndex"].ToString());

                                if (!objBufferData.PLC2PCBuffer[intBufferIndex_Out].StnModeCode_CargoLoad &&
                                    objBufferData.PLC2PCBuffer[intBufferIndex_Out].Ready == (int)clsPLC2PCBuffer.enuReady.OutReady &&
                                    string.IsNullOrWhiteSpace(objBufferData.PLC2PCBuffer[intBufferIndex_Out].LeftCmdSno) &&
                                    objBufferData.PLC2PCBuffer[intBufferIndex_Out].StnMode == (int)clsPLC2PCBuffer.enuStnMode.None)
                                {
                                    if (funUpdateCmdTrace(CmdSno.CmdSno, clsCmdSts.cstrCmdSts_Start, clsTrace.cstrStoreOutTrace_ReleaseEquPLCCmd))
                                    {
                                        //if (funWritePC2PLCSingel(
                                        //    objBCRData[(intBufferIndex_Out + 1) / 2, clsBCR.enuBCRLoc.Once].BufferName,
                                        //    CmdSno.CmdSno,//序號
                                        //    "2", //模式
                                        //    "0",//初始通知
                                        //    clsFunNotice1.CMD_OK,
                                        //    clsFunNotice2.StnOutMode,
                                        //    clsFunNotice3.None
                                        //    ))
                                        if (funWritePC2PLCSingel(
                                                objBCRData[(intBufferIndex_Out - 1) / 2, clsBCR.enuBCRLoc.Once].BufferName,
                                                CmdSno.CmdSno,
                                                CmdSno.CmdMode.ToString(),
                                                CmdSno.IniNotice.ToString()

                                                ))
                                        {
                                            clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                                            SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                            SystemTraceLog.LogMessage = "Both Stock Out Cmd Initiated!";
                                            SystemTraceLog.LeftCmdSno = CmdSno.CmdSno_L;
                                            SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                            SystemTraceLog.Trace      = clsTrace.cstrStoreOutTrace_ReleaseEquPLCCmd;
                                            SystemTraceLog.StnNo      = CmdSno.CmdSno;
                                            funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                        }
                                    }
                                    else
                                    {
                                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            if (clsSystem.intBegin == 0)
                            {
                                clsSystem.intBegin = 1;
                                #region 更新Trace 、新增EQUCMD
                                if (clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin) == ErrDef.ProcSuccess)
                                {
                                    if (funUpdateCmdTrace(CmdSno.CmdSno, clsCmdSts.cstrCmdSts_Start, clsTrace.cstrStoreInTrace_ReleaseCraneCmd))
                                    {
                                        int intCrane = funStnNo2Crane(CmdSno.Stn_No);

                                        //將站口編號轉成Loc


                                        //將命令寫入EQUCMD
                                        if (funInsertEquCmd(intCrane, CmdSno.CmdSno, "4", funStnNo2Loc(CmdSno.Stn_No), funStnNo2Loc(CmdSno.NewLoc), CmdSno.Priority.ToString()))
                                        {
                                            clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                                            SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                            SystemTraceLog.LogMessage = "Transfer Cmd Initiated!";
                                            SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                                            SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                            SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_ReleaseCraneCmd;
                                            SystemTraceLog.CmdMode    = clsEquCmdMode.cstrStnToStn;
                                            funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                        }
                                        else
                                        {
                                            clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                            SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                            SystemTraceLog.LogMessage = "Release Equ Cmd Fail!";
                                            SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                                            SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                            SystemTraceLog.CmdMode    = clsEquCmdMode.cstrStnToStn;
                                            funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                        }
                                    }
                                    else
                                    {
                                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Update Transfer Cmd Trace Fail!";
                                        SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_ReleaseEquPLCCmd;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                }
                                #endregion 更新Trace 、新增EQUCMD
                                clsSystem.intBegin = 0;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (objDataTable != null)
                {
                    objDataTable.Clear();
                    objDataTable.Dispose();
                    objDataTable = null;
                }
                if (dicCmdSno != null)
                {
                    dicCmdSno.Clear();
                    dicCmdSno = null;
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 檢察Crane命令是否完成
        /// </summary>
        private void funStnToStn_CraneCmdFinish()
        {
            DataTable            objDataTable   = new DataTable();
            DataTable            objCmd         = new DataTable();
            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
            string strSQL = string.Empty;
            string strEM  = string.Empty;

            try
            {
                strSQL  = "SELECT DISTINCT CMD_SNO, TRACE FROM CMD_MST WHERE Cmd_Sno<>'' and CMD_MODE='4' AND CMD_STS='1'";
                strSQL += " AND TRACE='" + clsTrace.cstrStoreInTrace_ReleaseCraneCmd + "'";
                if (clsSystem.gobjDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                {
                    for (int intCount1 = 0; intCount1 < objDataTable.Rows.Count; intCount1++)
                    {
                        string strCmdSno = objDataTable.Rows[intCount1]["CMD_SNO"].ToString();
                        strSQL  = "SELECT * FROM EQUCMD WHERE CMDSNO='" + strCmdSno + "'";
                        strSQL += " AND RENEWFLAG <> 'F' AND CMDSTS='9'";
                        if (clsSystem.gobjDB.funGetDT(strSQL, ref objCmd, ref strEM) == ErrDef.ProcSuccess)
                        {
                            for (int intCount2 = 0; intCount2 < objCmd.Rows.Count; intCount2++)
                            {
                                string strCmdSts       = objCmd.Rows[intCount2]["CmdSts"].ToString();
                                string strCompleteCode = objCmd.Rows[intCount2]["CompleteCode"].ToString();

                                if (strCmdSts == clsCmdSts.cstrCmdSts_Completed && strCompleteCode.Substring(0, 1) == "W")
                                {
                                    #region Update Equ Cmd CmdSts
                                    strSQL = "UPDATE EQUCMD SET CMDSTS='0' WHERE CMDSNO='" + strCmdSno + "'";
                                    if (clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Crane Transfer Cmd Retry Success!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    else
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Crane Transfer Cmd Retry Fail!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    #endregion Update Equ Cmd CmdSts
                                }
                                else if (strCmdSts == clsCmdSts.cstrCmdSts_Completed && strCompleteCode == "E2")//Crane空出庫
                                {
                                    #region Update Cmd Trace CompletedWaitPost
                                    if (funUpdateCmdTrace(strCmdSno, clsCmdSts.cstrCmdSts_CompletedWaitPost, clsTrace.cstrStoreInTrace_CraneCmdFinish))
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Transfer Cmd Finish!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_CompletedWaitPost;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_CraneCmdFinish;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    else
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Update Transfer Cmd Trace Fail!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_CompletedWaitPost;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_ReleaseCraneCmd;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    #endregion Update Cmd Trace CompletedWaitPost
                                }
                                else if (strCmdSts == clsCmdSts.cstrCmdSts_Completed && strCompleteCode == "EF")//地上盤強制取消命令
                                {
                                    #region Update Cmd Trace CompletedWaitPost
                                    if (funUpdateCmdTrace(strCmdSno, clsCmdSts.cstrCmdSts_CompletedWaitPost, clsTrace.cstrStoreInTrace_CraneCmdFinish))
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Transfer Cmd Finish!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_CompletedWaitPost;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_CraneCmdFinish;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    else
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Update Transfer Cmd Trace Fail!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_CompletedWaitPost;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_ReleaseCraneCmd;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    #endregion Update Cmd Trace CompletedWaitPost
                                }
                                else if (strCmdSts == clsCmdSts.cstrCmdSts_Completed && strCompleteCode == "92")
                                {
                                    #region Update Cmd Trace CompletedWaitPost
                                    if (funUpdateCmdTrace(strCmdSno, clsCmdSts.cstrCmdSts_CompletedWaitPost, clsTrace.cstrStoreInTrace_CraneCmdFinish))
                                    {
                                        funDeleteEquCmd(strCmdSno);
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Transfer Cmd Finish!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_CompletedWaitPost;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_CraneCmdFinish;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    else
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Update Transfer Cmd Trace Fail!";
                                        SystemTraceLog.CmdSno     = strCmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_CompletedWaitPost;
                                        SystemTraceLog.Trace      = clsTrace.cstrStoreInTrace_ReleaseCraneCmd;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    #endregion Update Cmd Trace CompletedWaitPost
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                //objDataTable
                //objCmd = new
                if (objDataTable != null)
                {
                    objDataTable.Clear();
                    objDataTable.Dispose();
                    objDataTable = null;
                }
                if (objCmd != null)
                {
                    objCmd.Clear();
                    objCmd.Dispose();
                    objCmd = null;
                }
                if (SystemTraceLog != null)
                {
                    SystemTraceLog = null;
                }
            }
        }
        /// <summary>
        /// 自動搬送測試 (撿料模式)
        /// </summary>
        /// <param name="StnIndex">站口編號</param>
        private void funAutoRunTest1(int StnIndex)
        {
            string strSQL          = string.Empty;
            string strEM           = string.Empty;
            string strCNTS         = string.Empty;
            string strOutSideLoc   = string.Empty;
            string strInSideLoc    = string.Empty;
            string strSNO_I        = string.Empty;
            string strSNO_O        = string.Empty;
            string strOutSideLocID = string.Empty;
            string strInSideLocID  = string.Empty;
            string strCmdSno       = string.Empty;
            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
            clsStnDef            StnDef         = new clsStnDef();

            try
            {
                if (lstOutModeStnDef.Count <= StnIndex && StnIndex <= 0)
                {
                    return;
                }

                if (!lstOutModeStnDef.Exists(p => p.StnIndex == StnIndex))
                {
                    return;
                }
                else
                {
                    StnDef = lstOutModeStnDef.Find(p => p.StnIndex == StnIndex);
                }

                if (!objBufferData.PLC2PCBuffer[StnDef.BufferIndex].StnModeCode_CargoLoad &&
                    //!objBufferData.PLC2PCBuffer[StnDef.BufferIndex].StnModeCode_RightLoad &&
                    objBufferData.PLC2PCBuffer[StnDef.BufferIndex].Ready == (int)clsPLC2PCBuffer.enuReady.OutReady &&
                    string.IsNullOrWhiteSpace(objBufferData.PLC2PCBuffer[StnDef.BufferIndex].LeftCmdSno) &&
                    string.IsNullOrWhiteSpace(objBufferData.PLC2PCBuffer[StnDef.BufferIndex].RightCmdSno) &&
                    objBufferData.PLC2PCBuffer[StnDef.BufferIndex].CmdMode == (int)clsPLC2PCBuffer.enuCmdMode.None)
                {
                    strSQL  = "SELECT TOP 1 LOC FROM LOC_MST WHERE LOCSTS='E'";
                    strSQL += " AND LOC IN (SELECT LOC1 FROM LOC_MST WHERE LOCSTS='E')";
                    strSQL += " AND CRANE_NO='" + StnDef.CraneNo + "' AND CRANE_ROW IN (3,4)";
                    strSQL += " ORDER BY TRNDATE";
                    if (clsSystem.gobjDB.funGetScalar(strSQL, ref strOutSideLoc, ref strEM) == ErrDef.ProcSuccess)
                    {
                        strSQL = "SELECT COUNT(*) AS CNTS FROM CMD_MST WHERE Cmd_Sno<>'' and CMDSTS='0' AND STNNO='" + StnDef.StnNo + "'";
                        switch (StnDef.CraneNo)
                        {
                        case 1:
                            strSQL += " AND LOC <'050000'";
                            break;

                        case 2:
                            strSQL += " AND LOC >'050000' AND LOC < '090000'";
                            break;

                        case 3:
                            strSQL += " AND LOC >'090000'";
                            break;
                        }

                        if (clsSystem.gobjDB.funGetScalar(strSQL, ref strCNTS, ref strEM) == ErrDef.ProcSuccess)
                        {
                            if (int.Parse(strCNTS) == 0)
                            {
                                switch (StnIndex)
                                {
                                case 1:
                                case 4:
                                    strInSideLoc = (strOutSideLoc.Substring(0, 2) == "03" ? "01" : "02") + strOutSideLoc.Substring(2, 4);
                                    strSNO_I     = strInSideLoc.Substring(0, 2) == "01" ? "2" : "1";
                                    strSNO_O     = strInSideLoc.Substring(0, 2) == "01" ? "1" : "2";
                                    break;

                                case 2:
                                case 5:
                                    strInSideLoc = (strOutSideLoc.Substring(0, 2) == "07" ? "05" : "06") + strOutSideLoc.Substring(2, 4);
                                    strSNO_I     = (strInSideLoc.Substring(0, 2) == "05" ? "2" : "1");
                                    strSNO_O     = (strInSideLoc.Substring(0, 2) == "05" ? "1" : "2");
                                    break;

                                case 3:
                                case 6:
                                    strInSideLoc = (strOutSideLoc.Substring(0, 2) == "11" ? "09" : "10") + strOutSideLoc.Substring(2, 4);
                                    strSNO_I     = (strInSideLoc.Substring(0, 2) == "09" ? "2" : "1");
                                    strSNO_O     = (strInSideLoc.Substring(0, 2) == "09" ? "1" : "2");
                                    break;
                                }

                                strSQL = "SELECT LOCID FROM LOC_MST WHERE LOC='" + strOutSideLoc + "'";
                                if (clsSystem.gobjDB.funGetScalar(strSQL, ref strOutSideLocID, ref strEM) == ErrDef.ProcSuccess)
                                {
                                    strSQL = "SELECT LOCID FROM LOC_MST WHERE LOC='" + strInSideLoc + "'";
                                    if (clsSystem.gobjDB.funGetScalar(strSQL, ref strInSideLocID, ref strEM) == ErrDef.ProcSuccess)
                                    {
                                        strCmdSno = funGetCmdSno();
                                        if (!string.IsNullOrWhiteSpace(strCmdSno))
                                        {
                                            strSQL  = "INSERT INTO CMD_MST (CMDSNO, SNO, CMDSTS, PRT, CMDMODE, IOTYP, LOC, TRNDATE,";
                                            strSQL += " ACTTIME, PROGID, LOCID, TRACE, STNNO,SCAN) VALUES (";
                                            strSQL += "'" + strCmdSno + "', '" + strSNO_I + "', '0', '5', '3', '33', '" + strInSideLoc + "', ";
                                            strSQL += "'" + DateTime.Now.ToString("yyyy/MM/dd") + "', '" + DateTime.Now.ToString("HH:mm:ss") + "', ";
                                            strSQL += "'MainControl', '" + strInSideLocID + "', '0','" + StnDef.StnNo + "','Y')";
                                            clsSystem.funWriteExceptionLog("[funAutoRunTest1]", " [Begin-Start]", "");
                                            clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin);
                                            if (clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                            {
                                                strSQL  = "INSERT INTO CMD_MST (CMDSNO, SNO, CMDSTS, PRT, CMDMODE, IOTYP ,LOC, TRNDATE,";
                                                strSQL += " ACTTIME,PROGID,LOCID,TRACE,STNNO,SCAN) VALUES (";
                                                strSQL += "'" + strCmdSno + "', '" + strSNO_O + "', '0', '5', '3', '33', '" + strOutSideLoc + "', ";
                                                strSQL += "'" + DateTime.Now.ToString("yyyy/MM/dd") + "', '" + DateTime.Now.ToString("HH:mm:ss") + "', ";
                                                strSQL += "'MainControl', '" + strOutSideLocID + "', '0','" + StnDef.StnNo + "','Y')";
                                                if (clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                                {
                                                    strSQL  = "UPDATE LOC_MST SET LOCSTS='C', OLDSTS='E' WHERE LOCSTS='E' AND";
                                                    strSQL += " LOC IN ('" + strInSideLoc + "', '" + strOutSideLoc + "')";
                                                    if (clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                                    {
                                                        clsSystem.funWriteExceptionLog("[funAutoRunTest1]", " [Commit-Start]", "");
                                                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                                        SystemTraceLog.LogMessage = "Create Auto Run Command Success!";
                                                        SystemTraceLog.LeftCmdSno = strCmdSno;
                                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                                        SystemTraceLog.CmdMode    = clsEquCmdMode.cstrLocToLoc;
                                                        SystemTraceLog.LocID      = strInSideLoc;
                                                        SystemTraceLog.LocID     += ", " + strOutSideLoc;
                                                        SystemTraceLog.StnNo      = StnDef.StnNo;
                                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);

                                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                                        SystemTraceLog.LogMessage = "Reserve Auto Run Loc Success!";
                                                        SystemTraceLog.LeftCmdSno = strCmdSno;
                                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                                        SystemTraceLog.CmdMode    = clsEquCmdMode.cstrLocToLoc;
                                                        SystemTraceLog.LocID      = strInSideLoc;
                                                        SystemTraceLog.LocID     += ", " + strOutSideLoc;
                                                        SystemTraceLog.StnNo      = StnDef.StnNo;
                                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                                    }
                                                    else
                                                    {
                                                        clsSystem.funWriteExceptionLog("[funAutoRunTest1]", " [Rollback-Start]", "");
                                                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                                        SystemTraceLog.LogMessage = "Reserve Auto Run Loc Fail!";
                                                        SystemTraceLog.LeftCmdSno = strCmdSno;
                                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                                        SystemTraceLog.CmdMode    = clsEquCmdMode.cstrLocToLoc;
                                                        SystemTraceLog.LocID      = strInSideLoc;
                                                        SystemTraceLog.LocID     += ", " + strOutSideLoc;
                                                        SystemTraceLog.StnNo      = StnDef.StnNo;
                                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                                    }
                                                }
                                                else
                                                {
                                                    clsSystem.funWriteExceptionLog("[funAutoRunTest1]", " [Rollback-Start]", "");
                                                    clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                                    SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                                    SystemTraceLog.LogMessage = "Create Auto Run Command Fail!";
                                                    SystemTraceLog.LeftCmdSno = strCmdSno;
                                                    SystemTraceLog.SNO        = strSNO_O;
                                                    SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                                    SystemTraceLog.CmdMode    = clsEquCmdMode.cstrLocToLoc;
                                                    SystemTraceLog.LocID      = strInSideLoc;
                                                    SystemTraceLog.LocID     += ", " + strOutSideLoc;
                                                    SystemTraceLog.StnNo      = StnDef.StnNo;
                                                    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                                }
                                            }
                                            else
                                            {
                                                clsSystem.funWriteExceptionLog("[funAutoRunTest1]", " [Rollback-Start]", "");
                                                clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                                SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                                SystemTraceLog.LogMessage = "Create Auto Run Command Fail!";
                                                SystemTraceLog.LeftCmdSno = strCmdSno;
                                                SystemTraceLog.SNO        = strSNO_I;
                                                SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Init;
                                                SystemTraceLog.CmdMode    = clsEquCmdMode.cstrLocToLoc;
                                                SystemTraceLog.LocID      = strInSideLoc;
                                                SystemTraceLog.LocID     += ", " + strOutSideLoc;
                                                SystemTraceLog.StnNo      = StnDef.StnNo;
                                                funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                            }
                                        }
                                        else
                                        {
                                            SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                            SystemTraceLog.LogMessage = "Create Auto Run Command Fail!";
                                            SystemTraceLog.LeftCmdSno = "Can't Get Cmd Sno!";
                                            funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                        }
                                    }
                                    else
                                    {
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Create Auto Run Command Fail!";
                                        SystemTraceLog.LeftCmdSno = "Can't Get InSideLoc!";
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                }
                                else
                                {
                                    SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                    SystemTraceLog.LogMessage = "Create Auto Run Command Fail!";
                                    SystemTraceLog.LeftCmdSno = "Can't Get OutSideLocID!";
                                    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                clsSystem.funWriteExceptionLog("[funAutoRunTest1]", " Exception [Rollback-Start]", "");
                clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
        }
        /// <summary>
        /// 自動搬送測試 (庫對庫模式)
        /// </summary>
        /// <param name="StnIndex"></param>
        private void funAutoRunTest2(int CraneNo)
        {
            string               strSQL         = string.Empty;
            string               strEM          = string.Empty;
            string               strCNTS        = string.Empty;
            string               strLoc         = string.Empty;
            string               strLocID       = string.Empty;
            string               strNewLoc      = string.Empty;
            string               strCmdSno      = string.Empty;
            string               strLocSize     = string.Empty;
            int                  intLocRow      = 0;
            DataTable            objLoc         = new DataTable();
            clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.None);

            try
            {
                if (CraneNo <= 0 && CraneNo > 3)
                {
                    return;
                }

                strSQL = "SELECT COUNT(*) AS CNTS FROM CMD_MST WHERE Cmd_Sno<>'' and CMDSTS='0'";
                switch (CraneNo)
                {
                    #region Crane儲位範圍
                case 1:
                    strSQL += " AND LOC <'050000'";
                    break;

                case 2:
                    strSQL += " AND LOC >'050000' AND LOC < '090000'";
                    break;

                case 3:
                    strSQL += " AND LOC >'090000'";
                    break;
                    #endregion Crane儲位範圍
                }
                if (clsSystem.gobjDB.funGetScalar(strSQL, ref strCNTS, ref strEM) == ErrDef.ProcSuccess)
                {
                    if (int.Parse(strCNTS) == 0)
                    {
                        strSQL = "SELECT TOP 1 LOC, LocID, CRANE_ROW,Loc_Size FROM LOC_MST WHERE LOCSTS='E'";
                        switch (CraneNo)
                        {
                            #region Crane儲位範圍
                        case 1:
                            strSQL += " AND LOC <'050000'";
                            break;

                        case 2:
                            strSQL += " AND LOC >'050000' AND LOC < '090000'";
                            break;

                        case 3:
                            strSQL += " AND LOC >'090000'";
                            break;

                        default:
                            return;

                            #endregion Crane儲位範圍
                        }
                        strSQL += " ORDER BY TRNDATE";
                        if (clsSystem.gobjDB.funGetDT(strSQL, ref objLoc, ref strEM) == ErrDef.ProcSuccess)
                        {
                            strLoc    = objLoc.Rows[0]["LOC"].ToString();
                            strLocID  = objLoc.Rows[0]["LocID"].ToString();
                            intLocRow = int.Parse(objLoc.Rows[0]["CRANE_ROW"].ToString());
                            strNewLoc = funGetEmptyLoc(CraneNo, intLocRow, clsLocSts.cstrLoc_ENNE, true, true, strLocSize, ref strSQL);
                            if (string.IsNullOrWhiteSpace(strNewLoc))
                            {
                                strNewLoc = funGetEmptyLoc(CraneNo, intLocRow, clsLocSts.cstrLoc_NNNN, false, true, strLocSize, ref strSQL);
                            }

                            if (!string.IsNullOrWhiteSpace(strNewLoc))
                            {
                                //strCmdSno = funGetCmdSno();
                                //if(!string.IsNullOrWhiteSpace(strCmdSno))
                                //{
                                //    strSQL = "UPDATE LOC_MST SET LOCSTS = 'O',OLDSTS = 'E'  WHERE LOC = '" + strLoc + "' AND LOCSTS = 'E'";
                                //    clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin);
                                //    if(clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                //    {
                                //        strSQL = "UPDATE LOC_MST SET LOCSTS = 'I',OLDSTS = 'N' WHERE LOC = '" + strNewLoc + "' AND LOCSTS = 'N' ";
                                //        if(clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                //        {
                                //            strSQL = "INSERT INTO CMD_MST (CMDSNO, SNO, CMDSTS, PRT, CMDMODE, IOTYP, LOC, TRNDATE,";
                                //            strSQL += " ACTTIME, PROGID, LOCID, TRACE, STNNO,SCAN) VALUES (";
                                //            strSQL += "'" + strCmdSno + "1', '0', '5', '3', '33', '" + strLoc + "', ";
                                //            strSQL += "'" + DateTime.Now.ToString("yyyy/MM/dd") + "', '" + DateTime.Now.ToString("HH:mm:ss") + "', ";
                                //            strSQL += "'MainControl', '" + strLocID + "', '0','','Y')";
                                //            if(clsSystem.gobjDB.funExecSql(strSQL, ref strEM) == ErrDef.ProcSuccess)
                                //            {
                                //            }
                                //        }
                                //    }
                                //}
                                //else
                                //{
                                //    SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);
                                //    SystemTraceLog.LogMessage = "Create Auto Run Command Fail!";
                                //    SystemTraceLog.LeftCmdSno = "Can't Get Cmd Sno!";
                                //    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
        }
        /// <summary>
        /// 從特定位置寫入 PC->PLC
        /// </summary>
        /// <param name="BufferName"></param>
        /// <param name="Section"></param>
        /// <param name="PLCValues"></param>
        /// <returns></returns>
        private bool funWritePC2PLCSingel(int iPLCNo, string BufferName, clsPLC.enuAddressSection Section, params string[] PLCValues)
        {
            string strAddress = string.Empty;

            if (funGetWritePC2PLCAddress(BufferName, Section, ref strAddress))
            {
                switch (iPLCNo)
                {
                case 1:
                    if (clsSystem.gobjPLC.funWritePLC(strAddress, PLCValues))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage     = "Write PLC Success!";
                        SystemTraceLog.BufferName     = BufferName;
                        SystemTraceLog.AddressSection = Section.ToString();
                        SystemTraceLog.PLCValues      = PLCValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(true);
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage     = "Write PLC Fail!";
                        SystemTraceLog.BufferName     = BufferName;
                        SystemTraceLog.AddressSection = Section.ToString();
                        SystemTraceLog.PLCValues      = PLCValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(false);
                    }
                    break;

                case 2:
                    if (clsSystem.gobjPLC2.funWritePLC(strAddress, PLCValues))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage     = "Write PLC Success!";
                        SystemTraceLog.BufferName     = BufferName;
                        SystemTraceLog.AddressSection = Section.ToString();
                        SystemTraceLog.PLCValues      = PLCValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(true);
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage     = "Write PLC Fail!";
                        SystemTraceLog.BufferName     = BufferName;
                        SystemTraceLog.AddressSection = Section.ToString();
                        SystemTraceLog.PLCValues      = PLCValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(false);
                    }
                    break;

                case 3:
                    if (clsSystem.gobjPLC3.funWritePLC(strAddress, PLCValues))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage     = "Write PLC Success!";
                        SystemTraceLog.BufferName     = BufferName;
                        SystemTraceLog.AddressSection = Section.ToString();
                        SystemTraceLog.PLCValues      = PLCValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(true);
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage     = "Write PLC Fail!";
                        SystemTraceLog.BufferName     = BufferName;
                        SystemTraceLog.AddressSection = Section.ToString();
                        SystemTraceLog.PLCValues      = PLCValues;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(false);
                    }
                    break;
                }
                return(false);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 寫入 PC->PLC
        /// </summary>
        /// <param name="BufferName"></param>
        /// <param name="Values"></param>
        /// <returns></returns>
        private bool funWritePC2PLCSingel(string BufferName, params string[] Values)
        {
            string strAddress = string.Empty;

            if (funGetWritePC2PLCAddress(BufferName, ref strAddress))
            {
                if (BufferName.Substring(0, 1) == "A" || BufferName.Substring(0, 1) == "B")
                {
                    if (clsSystem.gobjPLC.funWritePLC(strAddress, Values))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC Success!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = Values;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(true);
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC Fail!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = Values;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(false);
                    }
                }
                else if (BufferName.Substring(0, 1) == "C" || BufferName.Substring(0, 1) == "D" || BufferName.Substring(0, 1) == "E")
                {
                    if (clsSystem.gobjPLC2.funWritePLC(strAddress, Values))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC Success!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = Values;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(true);
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC Fail!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = Values;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(false);
                    }
                }
                else
                {
                    if (clsSystem.gobjPLC3.funWritePLC(strAddress, Values))
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC Success!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = Values;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(true);
                    }
                    else
                    {
                        clsTraceLogEventArgs SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.MPLC);
                        SystemTraceLog.LogMessage = "Write PLC Fail!";
                        SystemTraceLog.BufferName = BufferName;
                        SystemTraceLog.PLCValues  = Values;
                        funShowSystemTrace(lsbMPLC, SystemTraceLog, true);
                        SystemTraceLog = null;
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 庫對庫-寫入Crane命令
        /// </summary>
        private void funLocToLoc_ReleaseCraneCmd()
        {
            string    strSQL       = string.Empty;
            string    strEM        = string.Empty;
            DataTable objDataTable = new DataTable();
            Dictionary <string, clsCmdSno> dicCmdSno      = new Dictionary <string, clsCmdSno>();
            clsTraceLogEventArgs           SystemTraceLog = new clsTraceLogEventArgs(enuTraceLog.System);

            try
            {
                //strSQL = "SELECT * FROM CMD_MST WHERE CMDMODE='5' AND CMDSTS='0' AND TRACE='0' ORDER BY CMDSNO, LOC, PRT, TRNDATE DESC";
                strSQL = "SELECT * FROM CMD_MST WHERE Cmd_Sno<>'' and CMD_MODE ='5' AND CMD_STS = '0' AND TRACE ='0' ORDER BY CMD_SNO ,LOC,PRTY,Crt_Date DESC";
                if (clsSystem.gobjDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                {
                    #region 取得命令
                    for (int intCount = 0; intCount < objDataTable.Rows.Count; intCount++)
                    {
                        if (dicCmdSno.ContainsKey(objDataTable.Rows[intCount]["CMD_SNO"].ToString()))
                        {
                            string strCmdSno = objDataTable.Rows[intCount]["CMD_SNO"].ToString();
                            dicCmdSno[strCmdSno].CmdSno = objDataTable.Rows[intCount]["CMD_SNO"].ToString();
                            dicCmdSno[strCmdSno].Loc    = objDataTable.Rows[intCount]["LOC"].ToString();
                            dicCmdSno[strCmdSno].NewLoc = objDataTable.Rows[intCount]["NEW_LOC"].ToString();
                        }
                        else
                        {
                            clsCmdSno CmdSno = new clsCmdSno();
                            CmdSno.CmdSno   = objDataTable.Rows[intCount]["CMD_SNO"].ToString();
                            CmdSno.Loc      = objDataTable.Rows[intCount]["LOC"].ToString();
                            CmdSno.NewLoc   = objDataTable.Rows[intCount]["NEW_LOC"].ToString();
                            CmdSno.Priority = int.Parse(objDataTable.Rows[intCount]["PRTY"].ToString());
                            dicCmdSno.Add(CmdSno.CmdSno, CmdSno);
                        }
                    }
                    #endregion 取得命令

                    foreach (clsCmdSno CmdSno in dicCmdSno.Values)
                    {
                        #region 判斷是否為同Crane庫對庫命令
                        string strLoc_Row = CmdSno.Loc.Substring(0, 2);
                        //Leon  int intCrane = ((int.Parse(strLoc_Row) + 3) / 2);

                        int intCrane = ((int.Parse(strLoc_Row) - 1) / 2 + 1);
                        strLoc_Row = CmdSno.NewLoc.Substring(0, 2);

                        //Leon int intNewCrane = ((int.Parse(strLoc_Row) + 3) / 4);
                        int    intNewCrane = ((int.Parse(strLoc_Row) - 1) / 2 + 1);
                        string Source      = string.Empty;

                        string Destination = string.Empty;
                        Source      = CmdSno.Loc;
                        Destination = CmdSno.NewLoc;

                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                        SystemTraceLog.LogMessage = "Find Transfer Cmd Success!";
                        SystemTraceLog.LeftCmdSno = CmdSno.CmdSno_L;
                        SystemTraceLog.LocID      = Source;
                        SystemTraceLog.NewLocID   = Destination;
                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);

                        if (clsSystem.intBegin == 0)
                        {
                            clsSystem.intBegin = 1;
                            #region 更新Trace 和 EQUCMD
                            clsSystem.funWriteExceptionLog("[funLocToLoc_ReleaseCraneCmd]", "更新Trace 和 EQUCMD [Begin-Start]", " CmdSno=" + CmdSno.CmdSno);

                            if (clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Begin) == ErrDef.ProcSuccess)
                            {
                                if (funUpdateCmdTrace(CmdSno.CmdSno, clsCmdSts.cstrCmdSts_Start, clsTrace.cstrLocToLocTrace_ReleaseCraneCmd))
                                {
                                    //將命令寫入EQUCMD
                                    if (funInsertLocToLocEquCmd(intCrane, CmdSno.CmdSno, Source, Destination, CmdSno.Priority.ToString()))
                                    {
                                        clsSystem.funWriteExceptionLog("[funLocToLoc_ReleaseCraneCmd]", "更新Trace 和 EQUCMD [Commit-Start]", " CmdSno=" + CmdSno.CmdSno);
                                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Commit);
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Transfer Cmd Initiated!";
                                        SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                        SystemTraceLog.Trace      = clsTrace.cstrLocToLocTrace_ReleaseCraneCmd;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                    else
                                    {
                                        clsSystem.funWriteExceptionLog("[funLocToLoc_ReleaseCraneCmd]", "更新Trace 和 EQUCMD [Rollback-Start] Release Equ Cmd Fail!", " CmdSno=" + CmdSno.CmdSno);
                                        clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                        SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                        SystemTraceLog.LogMessage = "Release Equ Cmd Fail!";
                                        SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                                        SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                        SystemTraceLog.CmdMode    = clsEquCmdMode.cstrInMode;
                                        funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                    }
                                }
                                else
                                {
                                    clsSystem.funWriteExceptionLog("[funLocToLoc_ReleaseCraneCmd]", "更新Trace 和 EQUCMD [Rollback-Start] Update Transfer Cmd Trace Fail!", " CmdSno=" + CmdSno.CmdSno);

                                    clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                                    SystemTraceLog            = new clsTraceLogEventArgs(enuTraceLog.System);
                                    SystemTraceLog.LogMessage = "Update Transfer Cmd Trace Fail!";
                                    SystemTraceLog.CmdSno     = CmdSno.CmdSno;
                                    SystemTraceLog.CmdSts     = clsCmdSts.cstrCmdSts_Start;
                                    SystemTraceLog.Trace      = clsTrace.cstrLocToLocTrace_ReleaseCraneCmd;
                                    funShowSystemTrace(lsbSystemTrace, SystemTraceLog, true);
                                }
                            }

                            #endregion 更新Trace 和 EQUCMD
                            clsSystem.intBegin = 0;
                        }
                        #endregion 判斷是否為同Crane庫對庫命令
                    }
                }
            }
            catch (Exception ex)
            {
                clsSystem.funWriteExceptionLog("[funLocToLoc_ReleaseCraneCmd]", "更新 Trace 和 EQUCMD Exception [Rollback-Start]", "");

                clsSystem.gobjDB.funCommitCtrl(DB.enuTrnType.Rollback);
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (objDataTable != null)
                {
                    objDataTable.Clear();
                    objDataTable.Dispose();
                    objDataTable = null;
                }
                if (dicCmdSno != null)
                {
                    dicCmdSno.Clear();
                    dicCmdSno = null;
                }
                if (SystemTraceLog != null)
                {
                    SystemTraceLog = null;
                }
            }
        }