public List <C_SAP_STATION_MAP> GetSAPStationMapBySkuOrderBySAPCodeASC(string SkuNo, OleExec DB)
        {
            List <C_SAP_STATION_MAP> mapList = new List <C_SAP_STATION_MAP>();
            string                sql        = string.Empty;
            DataTable             dt         = new DataTable();
            Row_C_SAP_STATION_MAP row        = null;
            C_SAP_STATION_MAP     map        = null;

            if (DBType.Equals(DB_TYPE_ENUM.Oracle))
            {
                sql = $@"SELECT * FROM C_SAP_STATION_MAP WHERE SKUNO='{SkuNo}' ORDER BY SAP_STATION_CODE ASC";
                dt  = DB.ExecSelect(sql).Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    row = (Row_C_SAP_STATION_MAP)NewRow();
                    row.loadData(dr);
                    map = row.GetDataObject();
                    mapList.Add(map);
                }
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }

            return(mapList);
        }
        public string GetMAXSAPStationCodeBySkuAndWorkorderType(string SkuNo, string WorkorderType, OleExec DB)
        {
            string                result = "";
            string                sql    = string.Empty;
            DataTable             dt     = new DataTable();
            Row_C_SAP_STATION_MAP row    = null;
            C_SAP_STATION_MAP     map    = null;

            if (DBType.Equals(DB_TYPE_ENUM.Oracle))
            {
                sql = $@"SELECT MAX(SAP_STATION_CODE) FROM C_SAP_STATION_MAP WHERE SKUNO='{SkuNo}' AND WORKORDER_TYPE='{WorkorderType}' ORDER BY EDIT_TIME";
                dt  = DB.ExecSelect(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    result = dt.Rows[0][0].ToString();
                }
                else
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { SkuNo + "," + WorkorderType });
                    throw new MESReturnMessage(errMsg);
                }
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
            return(result);
        }
        public string DeleteSAPStationMap(string ID, OleExec sfcdb)
        {
            string result             = string.Empty;
            string DeleteString       = string.Empty;
            Row_C_SAP_STATION_MAP row = (Row_C_SAP_STATION_MAP)NewRow();
            string    sql             = string.Empty;
            DataTable dt = new DataTable();

            if (DBType.Equals(DB_TYPE_ENUM.Oracle))
            {
                sql = $@"SELECT * FROM C_SAP_STATION_MAP WHERE ID='{ID}'";
                dt  = sfcdb.ExecSelect(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    row.loadData(dt.Rows[0]);
                    DeleteString = row.GetDeleteString(DBType);
                    result       = sfcdb.ExecSQL(DeleteString);
                }
                else
                {
                    result = "0";
                }
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
            return(result);
        }
        /// <summary>
        /// 增、刪、改 SAP 與 站位的映射
        /// </summary>
        /// <param name="Map"></param>
        /// <param name="Operation"></param>
        /// <param name="Bu"></param>
        /// <param name="DB"></param>
        /// <returns></returns>
        public string UpdateSAPStationMap(C_SAP_STATION_MAP Map, string Operation, string Bu, OleExec DB)
        {
            string sql                  = string.Empty;
            string result               = string.Empty;
            Row_C_SAP_STATION_MAP row   = (Row_C_SAP_STATION_MAP)NewRow();
            T_C_SAP_STATION_MAP   table = new T_C_SAP_STATION_MAP(DB, DBType);

            if (DBType.Equals(DB_TYPE_ENUM.Oracle))
            {
                if (Map.ID != null && !Map.ID.Equals(""))
                {
                    row = (Row_C_SAP_STATION_MAP)GetObjByID(Map.ID, DB);
                }

                row.SKUNO            = Map.SKUNO;
                row.STATION_NAME     = Map.STATION_NAME;
                row.WORKORDER_TYPE   = Map.WORKORDER_TYPE;
                row.SAP_STATION_CODE = Map.SAP_STATION_CODE;
                row.EDIT_EMP         = Map.EDIT_EMP;
                row.EDIT_TIME        = Map.EDIT_TIME;

                switch (Operation.ToUpper())
                {
                case "ADD":
                    row.ID = GetNewID(Bu, DB);
                    sql    = row.GetInsertString(DBType);
                    break;

                case "UPDATE":
                    sql = row.GetUpdateString(DBType);
                    break;

                case "DELETE":
                    sql = row.GetDeleteString(DBType);
                    break;

                default:
                    sql = $@"SELECT * FROM C_SAP_STATION_MAP";
                    break;
                }
                result = DB.ExecSQL(sql);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }

            return(result);
        }