Esempio n. 1
0
        public void RegisterShelfManagementEvent()
        {
            Post["ShelfDef/{Action}/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                string action     = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic          d                = JsonConvert.DeserializeObject(resultJson);
                string           shelf_id         = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = action,
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    switch (action)
                    {
                    case "EnableUpdate":
                        bool   enable = d.enable?.Value;
                        string s      = scApp.TransferService.Manual_ShelfEnable(shelf_id, enable);
                        isSuccess = s == "OK" ? true : false;
                        result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                        break;

                    case "PriorityUpdate":
                        int priority = (int)d.priority?.Value;
                        isSuccess = scApp.ShelfService.doUpdatePriority(shelf_id, priority);
                        result    = isSuccess ? "OK" : "Update Shlef Priority failed.";
                        break;

                    case "MultiEnableUpdate":
                        var enableJson = JsonConvert.DeserializeObject <List <ShelfDef> >(resultJson);
                        result = "Update these Shlef Enable failed.\n";
                        enableJson.ForEach(x =>
                        {
                            string enableStr = scApp.TransferService.Manual_ShelfEnable(x.ShelfID, true);
                            isSuccess        = enableStr == "OK" ? true : false;

                            if (!isSuccess)
                            {
                                result    += $"{x.ShelfID}   ";
                                allSuccess = false;
                            }
                        });
                        if (allSuccess == true)
                        {
                            result = "OK";
                        }
                        break;

                    case "MultiDisableUpdate":
                        var disableJson = JsonConvert.DeserializeObject <List <ShelfDef> >(resultJson);
                        result = "Update these Shlef Disable failed.\n";
                        disableJson.ForEach(x =>
                        {
                            string ss = scApp.TransferService.Manual_ShelfEnable(x.ShelfID, false);
                            isSuccess = ss == "OK" ? true : false;

                            if (!isSuccess)
                            {
                                result    += $"{x.ShelfID}   ";
                                allSuccess = false;
                            }
                        });
                        if (allSuccess == true)
                        {
                            result = "OK";
                        }
                        break;

                    case "StateUpdate":
                        string state = d.state?.Value;
                        isSuccess = scApp.ShelfService.doUpdateState(shelf_id, state);
                        result    = isSuccess ? "OK" : "Update Shlef State failed.";
                        break;

                    case "RemarkUpdate":
                        string remark = d.remark?.Value;
                        isSuccess = scApp.ShelfService.doUpdateRemark(shelf_id, remark);
                        result    = isSuccess ? "OK" : "Update Shlef Remark failed.";
                        break;
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
Esempio n. 2
0
        private void RegisterZoneDefEvent()
        {
            Post["ZoneDef/{Action}/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                string action     = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                string returnStr  = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic          d                = JsonConvert.DeserializeObject(resultJson);
                string           zone_id          = d.zone_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = action,
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    switch (action)
                    {
                    case "LowWaterUpdate":
                        int lowwater = (int)d.water?.Value;
                        isSuccess = scApp.ZoneDefBLL.updateLowWater(zone_id, lowwater);
                        result    = isSuccess ? "OK" : "Update Zone LowWater failed.";
                        break;

                    case "HighWaterUpdate":
                        int highwater = (int)d.water?.Value;
                        isSuccess = scApp.ZoneDefBLL.updateHighWater(zone_id, highwater);
                        result    = isSuccess ? "OK" : "Update Zone HighWater failed.";
                        break;

                    case "ColorUpdate":
                        string color = d.color?.Value;
                        isSuccess = scApp.ZoneDefBLL.updateColor(zone_id, color);
                        result    = isSuccess ? "OK" : "Update Zone Color failed.";
                        break;
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
Esempio n. 3
0
        private void RegisterPortDefEvent()
        {
            Post["PortDef/{Action}/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                string action     = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                string returnStr  = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic          d                = JsonConvert.DeserializeObject(resultJson);
                string           port_id          = d.port_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = action,
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    switch (action)
                    {
                    case "PriorityUpdate":
                        int priority = (int)d.priority?.Value;
                        returnStr = scApp.TransferService.Manual_SetPortPriority(port_id, priority);
                        isSuccess = returnStr == "OK" ? true : false;
                        result    = isSuccess ? "OK" : "Update Port Priority failed.";
                        break;

                    case "PortTypeUpdate":
                        int porttype = (int)d.porttype?.Value;
                        returnStr = scApp.TransferService.Manual_PortTypeChange(port_id, (E_PortType)porttype);
                        isSuccess = returnStr == "OK" ? true : false;
                        result    = isSuccess ? "OK" : "Update Port Type failed.";
                        break;

                    case "PortService":
                        int service = (int)d.service?.Value;
                        returnStr = scApp.TransferService.Manual_SetPortStatus(port_id, (E_PORT_STATUS)service);
                        isSuccess = returnStr == "OK" ? true : false;
                        result    = isSuccess ? "OK" : "Update Port Serveice failed.";
                        break;

                    case "PortRun":
                        isSuccess = scApp.TransferService.SetPortRun(port_id);
                        result    = isSuccess ? "OK" : "Set Port Run failed.";
                        break;

                    case "PortStop":
                        isSuccess = scApp.TransferService.SetPortStop(port_id);
                        result    = isSuccess ? "OK" : "Set Port Stop failed.";
                        break;

                    case "PortAlarrmReset":
                        isSuccess = scApp.TransferService.PortAlarrmReset(port_id);
                        result    = isSuccess ? "OK" : "Port Alarrm Reset failed.";
                        break;

                    case "PortCommandingTrue":
                        isSuccess = scApp.TransferService.PortCommanding(port_id, true);
                        result    = isSuccess ? "OK" : "Set Port Commanding failed.";
                        break;

                    case "PortCommandingFalse":
                        isSuccess = scApp.TransferService.PortCommanding(port_id, false);
                        result    = isSuccess ? "OK" : "Cancel Port Commanding failed.";
                        break;

                    case "toAGVMode":
                        isSuccess = scApp.TransferService.toAGV_Mode(port_id);
                        result    = isSuccess ? "OK" : "Set AGV Mode failed.";
                        break;

                    case "toMGVMode":
                        isSuccess = scApp.TransferService.toMGV_Mode(port_id);
                        result    = isSuccess ? "OK" : "Set MGV Mode failed.";
                        break;

                    case "setAGVBcrRead":
                        isSuccess = scApp.TransferService.SetAGV_PortBCR_Read(port_id);
                        result    = isSuccess ? "OK" : "Set AGV BCR Read failed.";
                        break;

                    case "resetAGVBcrRead":
                        isSuccess = scApp.TransferService.RstAGV_PortBCR_Read(port_id);
                        result    = isSuccess ? "OK" : "Reset AGV BCR Read failed.";
                        break;

                    case "rereadBCR":
                        isSuccess = true;                                 // todo Reread BCR
                        result    = isSuccess ? "OK" : "Reread BCR failed.";
                        break;

                    case "AGVOpenBox":
                        isSuccess = scApp.TransferService.SetAGV_PortOpenBOX(port_id, "CSTBoxControl");
                        result    = isSuccess ? "OK" : "Open AGV Box failed.";
                        break;

                    case "TimeOutForAutoUDUpdate":
                        int timeOutForAutoUD = (int)d.timeOutForAutoUD?.Value;
                        isSuccess = scApp.TransferService.doUpdateTimeOutForAutoUD(port_id, timeOutForAutoUD);
                        result    = isSuccess ? "OK" : "Update Port TimeOutForAutoUD failed.";
                        break;

                    case "TimeOutForAutoInZoneUpdate":
                        string timeOutForAutoInZone = d.timeOutForAutoInZone?.Value;
                        isSuccess = scApp.TransferService.doUpdateTimeOutForAutoInZone(port_id, timeOutForAutoInZone);
                        result    = isSuccess ? "OK" : "Update Port TimeOutForAutoInZone failed.";
                        break;

                    case "BlockPort":
                        isSuccess = scApp.TransferService.UpdateIgnoreModeChange(port_id, "Y");
                        result    = isSuccess ? "OK" : "Block Port failed.";
                        break;

                    case "UnblockPort":
                        isSuccess = scApp.TransferService.UpdateIgnoreModeChange(port_id, "N");
                        result    = isSuccess ? "OK" : "Unblock Port failed.";
                        break;

                    case "ClearAlarmPort":
                        isSuccess = scApp.TransferService.PortAlarrmReset(port_id);
                        result    = isSuccess ? "OK" : "Clear Alarm Port failed.";
                        break;
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
Esempio n. 4
0
        private void RegisterCassetteEvent()
        {
            Post["CassetteData/{Action}/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                string action     = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic          d                = JsonConvert.DeserializeObject(resultJson);
                string           box_id           = d.box_id?.Value;
                string           cst_id           = d.cst_id?.Value;
                string           cst_loc          = d.cst_loc?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action       = action,
                    UserID       = userid,
                    OldCarrierID = cst_id ?? string.Empty,
                    CarrierLoc   = cst_loc ?? string.Empty,
                    BOXID        = box_id ?? string.Empty,
                    ActionTime   = DateTime.Now,
                };
                try
                {
                    switch (action)
                    {
                    case "StateUpdate":
                        int state = (int)d.state?.Value;
                        isSuccess = scApp.CassetteDataBLL.UpdateCSTState(box_id, state);
                        result    = isSuccess ? "OK" : "Update Cassette State failed.";
                        break;

                    case "LocationUpdate":
                        string s  = scApp.TransferService.Manual_DeleteCst(cst_id, box_id);
                        string ss = scApp.TransferService.Manual_InsertCassette(cst_id, box_id, cst_loc);
                        if (s != "OK" || ss != "OK")
                        {
                            isSuccess = false;
                        }
                        result = isSuccess ? "OK" : "Update Cassette Location failed.";

                        break;

                    case "InstallCST_BOX":
                        CassetteData cassette = scApp.CassetteDataBLL.loadCassetteDataByCSTID(cst_id);
                        result = scApp.TransferService.Manual_InsertCassette(cst_id, box_id, cst_loc);
                        break;

                    case "RemoveCST_BOX":
                        string sss = scApp.TransferService.Manual_DeleteCst(cst_id, box_id);
                        isSuccess = sss == "OK" ? true : false;
                        result    = isSuccess ? "OK" : "Remove Cassette failed.";
                        break;

                    case "ScanCST_BOX":
                        string ssss = scApp.TransferService.SetScanCmd(cst_id, box_id, cst_loc);
                        isSuccess = ssss == "OK" ? true : false;
                        result    = isSuccess ? "OK" : "Remove Cassette failed.";
                        break;
                    }
                    ;
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
        private void RegisterVehilceEvent()
        {
            Get["AVEHICLES/{ID}"] = (p) =>
            {
                string   vh_id    = p.ID;
                AVEHICLE vh       = SCApplication.getInstance().VehicleBLL.getVehicleByID(vh_id);
                var      response = (Response)vh.ToString();
                response.ContentType = restfulContentType;

                return(response);
            };
            Get["AVEHICLES"] = (p) =>
            {
                string          vh_id    = p.ID;
                List <AVEHICLE> vhs      = SCApplication.getInstance().getEQObjCacheManager().getAllVehicle();
                var             response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };
            //Get["AVEHICLES/(?<all>)"] = (p) =>
            Get["AVEHICLES/_search"] = (p) =>
            {
                List <AVEHICLE> vhs = null;

                foreach (string name in Request.Query)
                {
                    switch (name)
                    {
                    case "SectionID":
                        string sec_id = Request.Query[name] ?? string.Empty;
                        vhs = SCApplication.getInstance().VehicleBLL.loadVehicleBySEC_ID(sec_id);
                        break;
                    }
                }
                var response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["metrics"] = (p) =>
            {
                int total_idle_vh_clean        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Clean);
                int total_idle_vh_Dirty        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Dirty);
                int total_cmd_is_queue_count   = SCApplication.getInstance().CMDBLL.getCMD_MCSIsQueueCount();
                int total_cmd_is_running_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsRunningCount();

                string ohxc_excute_info = string.Empty;

                StringBuilder sb = new StringBuilder();
                setOhxCContent(sb, nameof(total_idle_vh_clean), total_idle_vh_clean, "current idle clean car");
                setOhxCContent(sb, nameof(total_idle_vh_Dirty), total_idle_vh_Dirty, "current idle dirty car");
                setOhxCContent(sb, nameof(total_cmd_is_queue_count), total_cmd_is_queue_count, "cmd number being queued");
                setOhxCContent(sb, nameof(total_cmd_is_running_count), total_cmd_is_running_count, "cmd number being executed");

                var response = (Response)sb.ToString();
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ViewerUpdate"] = (p) =>
            {
                SCApplication   scApp = SCApplication.getInstance();
                List <AVEHICLE> vhs   = scApp.getEQObjCacheManager().getAllVehicle();

                //foreach (AVEHICLE vh in vhs)
                //{
                //    scApp.VehicleService.PublishVhInfo(vh, null);
                //    SpinWait.SpinUntil(() => false, 10);
                //}

                var response = (Response)"OK";
                response.ContentType = restfulContentType;
                return(response);
            };

            //Post["api/io/T2STK100T01/waitin/CST01"] = (p) =>
            //{
            //    var response = (Response)"OK";
            //    response.ContentType = restfulContentType;
            //    return response;
            //};

            Post["AVEHICLES/SendCommand"] = (p) =>
            {
                var        scApp        = SCApplication.getInstance();
                bool       isSuccess    = true;
                string     vh_id        = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string     cst_id       = Request.Query.cst_id.Value ?? Request.Form.cst_id.Value ?? string.Empty;
                string     box_id       = Request.Query.box_id.Value ?? Request.Form.box_id.Value ?? string.Empty;
                string     lot_id       = Request.Query.lot_id.Value ?? Request.Form.lot_id.Value ?? string.Empty;
                string     from_port_id = Request.Query.from_port_id.Value ?? Request.Form.from_port_id.Value ?? string.Empty;
                string     to_port_id   = Request.Query.to_port_id.Value ?? Request.Form.to_port_id.Value ?? string.Empty;
                E_CMD_TYPE e_cmd_type   = default(E_CMD_TYPE);
                string     cmd_type     = Request.Query.cmd_type.Value ?? Request.Form.cmd_type.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    ACMD_OHTC cmd_obj  = null;
                    AVEHICLE  assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    if (isSuccess)
                    {
                        isSuccess = Enum.TryParse(cmd_type, out e_cmd_type);
                        if (isSuccess)
                        {
                            switch (e_cmd_type)
                            {
                            case E_CMD_TYPE.Move:
                            case E_CMD_TYPE.Scan:
                            case E_CMD_TYPE.Load:
                            case E_CMD_TYPE.Unload:
                            case E_CMD_TYPE.LoadUnload:
                            case E_CMD_TYPE.MoveToMTL:
                            case E_CMD_TYPE.SystemOut:
                                string from_adr = "";
                                string to_adr   = "";
                                scApp.MapBLL.getAddressID(from_port_id, out from_adr);
                                scApp.MapBLL.getAddressID(to_port_id, out to_adr);

                                scApp.CMDBLL.doCreatTransferCommand(vh_id, out cmd_obj,
                                                                    cmd_type: e_cmd_type,
                                                                    source: from_port_id,
                                                                    destination: to_port_id,
                                                                    cst_id: cst_id,
                                                                    box_id: box_id,
                                                                    lot_id: lot_id,
                                                                    source_address: from_adr,
                                                                    destination_address: to_adr,
                                                                    gen_cmd_type: SCAppConstants.GenOHxCCommandType.Manual);
                                sc.BLL.CMDBLL.OHTCCommandCheckResult check_result_info =
                                    sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.OHTCCommandCheckResult>
                                        (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT);
                                isSuccess = check_result_info.IsSuccess;
                                result    = check_result_info.ToString();
                                if (isSuccess)
                                {
                                    isSuccess = scApp.VehicleService.doSendOHxCCmdToVh(assignVH, cmd_obj);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command to vehicle failed!";
                                    }
                                }
                                else
                                {
                                    result = "Command create failed!";
                                    //bcf.App.BCFApplication.onWarningMsg(this, new bcf.Common.LogEventArgs("Command create fail.", check_result_info.Num));
                                }
                                break;

                            case E_CMD_TYPE.Home:
                                string cmd_id = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual);
                                //isSuccess = scApp.VehicleService.TransferRequset(vh_id, cmd_id, ActiveType.Home,
                                //                                    "", "", "", new string[0], new string[0], new string[0], new string[0],
                                //                                    "", "", "", "");
                                break;

                            case E_CMD_TYPE.Teaching:
                                isSuccess = scApp.VehicleService.TeachingRequest(vh_id, from_port_id, to_port_id);
                                break;
                            }
                        }
                        else
                        {
                            result = $"Try parse Command Type:[{cmd_type}] failed!";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendReset"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    AVEHICLE assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Send vehicle status request failed.";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendCancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                //try
                //{
                //    AVEHICLE assignVH = null;

                //    assignVH = scApp.VehicleBLL.getVehicleByID(vh_id);

                //    isSuccess = assignVH != null;

                //    if (isSuccess)
                //    {
                //        string mcs_cmd_id = assignVH.MCS_CMD;
                //        if (!string.IsNullOrWhiteSpace(mcs_cmd_id))
                //        {
                //            ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                //            if (mcs_cmd == null)
                //            {
                //                result = $"Can't find MCS command:[{mcs_cmd_id}] in database.";
                //            }
                //            else
                //            {
                //                CMDCancelType actType = default(CMDCancelType);
                //                if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                //                {
                //                    actType = CMDCancelType.CmdCancel;
                //                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                //                    if (isSuccess) result = "OK";
                //                    else result = "Send command cancel/abort failed.";
                //                }
                //                else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                //                {
                //                    actType = CMDCancelType.CmdAbort;
                //                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                //                    if (isSuccess) result = "OK";
                //                    else result = "Send command cancel/abort failed.";
                //                }
                //                else
                //                {
                //                    result = $"MCS command:[{mcs_cmd_id}] can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                //                }
                //            }
                //        }
                //        else
                //        {
                //            string ohtc_cmd_id = assignVH.OHTC_CMD;
                //            if (string.IsNullOrWhiteSpace(ohtc_cmd_id))
                //            {
                //                result = $"Vehicle:[{vh_id}] do not have command.";
                //            }
                //            else
                //            {
                //                ACMD_OHTC ohtc_cmd = scApp.CMDBLL.getCMD_OHTCByID(ohtc_cmd_id);
                //                if (ohtc_cmd == null)
                //                {
                //                    result = $"Can't find vehicle command:[{ohtc_cmd_id}] in database.";
                //                }
                //                else
                //                {
                //                    CMDCancelType actType = ohtc_cmd.CMD_STAUS >= E_CMD_STATUS.Execution ? CMDCancelType.CmdAbort : CMDCancelType.CmdCancel;
                //                    isSuccess = scApp.VehicleService.doAbortCommand(assignVH, ohtc_cmd_id, actType);
                //                    if (isSuccess)
                //                    {
                //                        result = "OK";
                //                    }
                //                    else
                //                    {
                //                        result = "Send vehicle status request failed.";
                //                    }
                //                }
                //            }
                //        }
                //    }
                //    else
                //    {
                //        result = $"Vehicle :[{vh_id}] not found!";
                //    }
                //}
                //catch (Exception ex)
                //{
                //    isSuccess = false;
                //    result = "Execption happend!";
                //    logger.Error(ex, "Execption:");
                //}
                (isSuccess, result) = scApp.VehicleService.ProcessVhCmdCancelAbortRequest(vh_id);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseEvent"] = (p) =>
            {
                bool          isSuccess  = false;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                PauseEvent    pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(event_type, out pauseEvent);
                if (isSuccess)
                {
                    isSuccess = scApp.VehicleService.PauseRequest
                                    (vh_id, pauseEvent, SCAppConstants.OHxCPauseType.Normal);
                }

                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseStatusChange"] = (p) =>
            {
                bool          isSuccess  = false;
                string        result     = string.Empty;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        pauseType  = Request.Query.pauseType.Value ?? Request.Form.pauseType.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                SCAppConstants.OHxCPauseType pause_type = default(SCAppConstants.OHxCPauseType);
                PauseEvent pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(pauseType, out pause_type);

                if (isSuccess)
                {
                    isSuccess = Enum.TryParse(event_type, out pauseEvent);

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.PauseRequest
                                        (vh_id, pauseEvent, pause_type);
                        if (isSuccess)
                        {
                            //AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            //vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Send pause request to vehicle:{vh_id} failed.";
                        }
                    }
                    else
                    {
                        result = $"Can't recognize Pause Event:{event_type}.";
                    }
                }
                else
                {
                    result = $"Can't recognize Pause Type:{pauseType}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ModeStatusChange"] = (p) =>
            {
                bool          isSuccess   = false;
                string        result      = string.Empty;
                SCApplication scApp       = SCApplication.getInstance();
                string        vh_id       = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        modeStatus  = Request.Query.modeStatus.Value ?? Request.Form.modeStatus.Value ?? string.Empty;
                VHModeStatus  mode_status = default(VHModeStatus);
                isSuccess = Enum.TryParse(modeStatus, out mode_status);

                if (isSuccess)
                {
                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleBLL.updataVehicleMode(vh_id, mode_status);
                        if (isSuccess)
                        {
                            AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Update vehicle:{vh_id} mode status failed.";
                        }
                    }
                }
                else
                {
                    result = $"Can't recognize mode status:{modeStatus}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ResetAlarm"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    //isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    isSuccess = scApp.TransferService.OHBC_AlarmAllCleared(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/Debug_Function"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string resuleJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resuleJson = reader.ReadToEnd();
                    }
                }
                var     fun_enable         = JsonConvert.DeserializeObject(resuleJson);
                JObject jo                 = JObject.Parse(resuleJson);
                dynamic dyna               = fun_enable as dynamic;
                var     func_num           = dyna.Func_Num?.Value ?? 0;
                string  func_name          = dyna.Func_Name?.Value ?? string.Empty;
                string  vh_id              = dyna.VH_ID?.Value ?? string.Empty;
                string  cst_id             = dyna.Cst_ID?.Value ?? string.Empty;
                string  from_adr           = dyna.From_Adr?.Value ?? string.Empty;
                string  to_adr             = dyna.To_Adr?.Value ?? string.Empty;
                var     operatingMode      = dyna.OperatingMode?.Value ?? null;
                var     operatingPowerMode = dyna.OperatingPowerMode?.Value ?? null;
                var     abort_type         = dyna.Abort_Type?.Value ?? null;
                var     pauseEvent         = dyna.PauseEvent?.Value ?? null;
                var     pauseType          = dyna.PauseType?.Value ?? null;
                var     blockzoneQueue     = dyna.BlockZoneQueue?.Value ?? null;
                var     pauseFirst         = dyna.PauseFirst?.Value ?? null;
                var     seg_id             = dyna.Seg_ID?.Value ?? null;
                //string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                var noticeCar = scApp.getEQObjCacheManager().getVehicletByVHID(vh_id);
                try
                {
                    if (func_num != 0)
                    {
                        if (func_num is Int64 i)
                        {
                            switch (i)
                            {
                            case 1:
                                asyExecuteAction(scApp.VehicleService.HostBasicVersionReport, vh_id);
                                break;

                            case 2:
                                asyExecuteAction(scApp.VehicleService.HostBasicVersionReport, vh_id);
                                break;

                            case 11:
                                asyExecuteAction(scApp.VehicleService.BasicInfoReport, vh_id);
                                break;

                            case 13:
                                asyExecuteAction(scApp.VehicleService.TavellingDataReport, vh_id);
                                break;

                            case 15:
                                asyExecuteAction(scApp.VehicleService.SectionDataReport, vh_id);
                                break;

                            case 17:
                                asyExecuteAction(scApp.VehicleService.AddressDataReport, vh_id);
                                break;

                            case 19:
                                asyExecuteAction(scApp.VehicleService.ScaleDataReport, vh_id);
                                break;

                            case 21:
                                asyExecuteAction(scApp.VehicleService.ControlDataReport, vh_id);
                                break;

                            case 23:
                                asyExecuteAction(scApp.VehicleService.GuideDataReport, vh_id);
                                break;

                            case 35:
                                scApp.VehicleService.CarrierIDRenameRequset(vh_id, noticeCar.CST_ID, cst_id);
                                break;

                            case 71:
                                scApp.VehicleService.TeachingRequest(vh_id, from_adr, to_adr);
                                break;

                            case 41:
                                OperatingVHMode vhMode = (OperatingVHMode)operatingMode;
                                scApp.VehicleService.ModeChangeRequest(vh_id, vhMode);
                                break;

                            case 45:
                                OperatingPowerMode powerMode = (OperatingPowerMode)operatingPowerMode;
                                scApp.VehicleService.PowerOperatorRequest(vh_id, operatingPowerMode);
                                break;

                            case 37:
                                CMDCancelType cmdCancelType = (CMDCancelType)abort_type;
                                noticeCar.sned_Str37(noticeCar.OHTC_CMD, abort_type);
                                break;

                            case 39:
                                PauseEvent _pauseEvent = (PauseEvent)pauseEvent;
                                PauseType  _pauseType  = (PauseType)pauseType;
                                scApp.VehicleService.PauseRequest(vh_id, _pauseEvent, pauseType);
                                break;

                            case 61:
                                asyExecuteAction(scApp.VehicleService.IndividualUploadRequest, vh_id);
                                break;

                            case 63:
                                asyExecuteAction(scApp.VehicleService.IndividualChangeRequest, vh_id);
                                break;

                            case 91:
                                asyExecuteAction(scApp.VehicleService.AlarmResetRequest, vh_id);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(func_name))
                    {
                        if (func_name is string str)
                        {
                            switch (str)
                            {
                            case "btn_SendAll":
                                asyExecuteAction(scApp.VehicleService.doDataSysc, vh_id);
                                break;

                            case "btn_reset_teach_result":
                                List <ASECTION> sections = scApp.CatchDataFromDB_Section;
                                foreach (var sec in sections)
                                {
                                    if (scApp.MapBLL.resetSecTechingTime(sec.SEC_ID))
                                    {
                                        sec.LAST_TECH_TIME = null;
                                    }
                                }
                                break;

                            case "btn_cmd_override_test":
                                scApp.VehicleService.VhicleChangeThePath(vh_id, pauseFirst);
                                break;

                            case "btn_Force_FinishCmd":
                                scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                                break;

                            case "btn_Refresh_Vh_Status":
                                scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                                break;

                            case "btn_forceReleaseAllBlock":
                                scApp.VehicleService.forceReleaseBlockControl(vh_id);
                                break;

                            case "btn_open_tcp_port":
                                scApp.VehicleService.startVehicleTcpIpServer(vh_id);
                                break;

                            case "btn_close_tcp_port":
                                scApp.VehicleService.stopVehicleTcpIpServer(vh_id);
                                break;

                            case "btn_changeToRemove":
                                if (!noticeCar.IS_INSTALLED)
                                {
                                    result = ($"{vh_id} is removed ready!");
                                    break;
                                }
                                scApp.VehicleService.Remove(vh_id);
                                result = $"{vh_id} remove ok";
                                break;

                            case "btn_changeToInstall":
                                if (noticeCar.IS_INSTALLED)
                                {
                                    result = ($"{vh_id} is install ready!");
                                    break;
                                }
                                scApp.VehicleService.Install(vh_id);
                                result = $"{vh_id} install ok";
                                break;

                            case "btn_changeToAutoRemote":
                                scApp.VehicleService.VehicleAutoModeCahnge(vh_id, VHModeStatus.AutoRemote);
                                break;

                            case "btn_changeToAutoLocal":
                                scApp.VehicleService.VehicleAutoModeCahnge(vh_id, VHModeStatus.AutoLocal);
                                break;

                            case "btn_forceReleaseALLBlock":
                                scApp.VehicleService.forceReleaseBlockControl();
                                break;

                            case "btn_release_block":
                                scApp.VehicleService.reCheckBlockControl(blockzoneQueue);
                                break;

                            case "btn_refresh_vh_order_in_seg":
                                var seg_obj = scApp.SegmentBLL.cache.GetSegment(seg_id);
                                seg_obj.RefreshVhOrder(scApp.VehicleBLL, scApp.SectionBLL);
                                break;

                            case "btn_portInServeice":

                                break;

                            case "btn_portOutOfServeice":

                                break;

                            default:
                                break;
                            }
                        }
                    }

                    isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["Engineer/ForceCmdFinish"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                bool   isSuccess = scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                if (isSuccess)
                {
                    var vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                    vh.NotifyVhExcuteCMDStatusChange();
                }
                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ScanSelected/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                //string action = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic d = JsonConvert.DeserializeObject(resultJson);
                //string shelf_id = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "ScanSelected",
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    var shelf = d.shelf;
                    foreach (string item in shelf)
                    {
                        if (scApp.TransferService.isShelfPort(item))
                        {
                            scApp.TransferService.SetScanCmd("", "", item);
                        }
                    }
                    //foreach (var v in )
                    //{
                    //	if (isShelfPort(v.Carrier_LOC))
                    //	{
                    //		SetScanCmd("", "", v.Carrier_LOC);
                    //	}
                    //}
                    //bool enable = d.enable?.Value;
                    //string s = scApp.TransferService.Manual_ShelfEnable(shelf_id, enable);
                    isSuccess = true;
                    result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ScanAll/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                //string action = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic d = JsonConvert.DeserializeObject(resultJson);
                //string shelf_id = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "ScanAll",
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    scApp.TransferService.ScanALL();
                    isSuccess = true;
                    result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
        private void RegisterUserControlEvent()
        {
            Post["UserControl/LogIn"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userID   = Request.Query.userID.Value ?? Request.Form.userID.Value ?? string.Empty;
                string password = Request.Query.password.Value ?? Request.Form.password.Value ?? string.Empty;
                try
                {
                    Boolean loginSuccess = false;
                    Boolean hasAuth      = false;
                    if (!SCUtility.isEmpty(userID))
                    {
                        loginSuccess = scApp.UserBLL.checkUserEnable(userID);
                    }
                    if (loginSuccess)
                    {
                        loginSuccess = scApp.UserBLL.checkUserPassword(userID, password);
                    }
                    if (loginSuccess)
                    {
                        hasAuth = scApp.UserBLL.checkUserAuthority(userID, SCAppConstants.FUNC_LOGIN);
                    }
                    if (!hasAuth)
                    {
                        result = "No authority!";
                    }
                    else
                    {
                        result = "OK";
                    }
                    //isSuccess = scApp.UserControlService.doChangeLinkStatus(linkStatus, out result);
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "LogIn",
                    ActionTime = DateTime.Now,
                    UserID     = userID,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["UserControl/Exit"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userID   = Request.Query.userID.Value ?? Request.Form.userID.Value ?? string.Empty;
                string password = Request.Query.password.Value ?? Request.Form.password.Value ?? string.Empty;
                try
                {
                    Boolean loginSuccess = false;
                    Boolean hasAuth      = false;
                    if (!SCUtility.isEmpty(userID))
                    {
                        loginSuccess = scApp.UserBLL.checkUserPassword(userID, password);
                    }
                    if (loginSuccess)
                    {
                        hasAuth = scApp.UserBLL.checkUserAuthority(userID, SCAppConstants.FUNC_CLOSE_SYSTEM);
                    }
                    if (!hasAuth)
                    {
                        result = "No authority!";
                    }
                    else
                    {
                        result = "OK";
                    }
                    //isSuccess = scApp.UserControlService.doChangeLinkStatus(linkStatus, out result);
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "LogOut",
                    ActionTime = DateTime.Now,
                    UserID     = userID,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["UserControl/UpdatePassword"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userID     = Request.Query.userID.Value ?? Request.Form.userID.Value ?? string.Empty;
                string password_o = Request.Query.password_O.Value ?? Request.Form.password_O.Value ?? string.Empty;
                string password_n = Request.Query.password_N.Value ?? Request.Form.password_N.Value ?? string.Empty;
                string password_v = Request.Query.password_V.Value ?? Request.Form.password_V.Value ?? string.Empty;
                try
                {
                    Boolean loginSuccess = false;
                    if (!SCUtility.isEmpty(userID))
                    {
                        loginSuccess = scApp.UserBLL.checkUserPassword(userID, password_o);
                    }
                    else
                    {
                        result = "User ID can not be is empty!";
                    }
                    if (loginSuccess)
                    {
                        if (SCUtility.isEmpty(password_v) || SCUtility.isEmpty(password_n))
                        {
                            result = "New password is empty!";
                        }
                        else
                        {
                            if (!SCUtility.isMatche(password_v, password_n))
                            {
                                result = "New password is not match!";
                            }
                            else
                            {
                                bool pdSuccess = scApp.UserBLL.updatePassword(userID, password_n);
                                if (pdSuccess)
                                {
                                    result = "OK";
                                }
                                else
                                {
                                    result = "Password update Fail.";
                                }
                            }
                        }
                    }
                    else
                    {
                        result = "Old password is not correct!";
                    }
                    //isSuccess = scApp.UserControlService.doChangeLinkStatus(linkStatus, out result);
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["UserControl/UserAccountAdd"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userID    = Request.Query.userID.Value ?? Request.Form.userID.Value ?? string.Empty;
                string userName  = Request.Query.userName.Value ?? Request.Form.userName.Value ?? string.Empty;
                string password  = Request.Query.password.Value ?? Request.Form.password.Value ?? string.Empty;
                string isDisable = Request.Query.isDisable.Value ?? Request.Form.isDisable.Value ?? string.Empty;
                //string isPowerUser = Request.Query.isPowerUser.Value ?? Request.Form.isPowerUser.Value ?? string.Empty;
                string userGrp = Request.Query.userGrp.Value ?? Request.Form.userGrp.Value ?? string.Empty;
                string badgeNo = Request.Query.badgeNo.Value ?? Request.Form.badgeNo.Value ?? string.Empty;
                //string isAdmin = Request.Query.isAdmin.Value ?? Request.Form.isAdmin.Value ?? string.Empty;
                string department = Request.Query.department.Value ?? Request.Form.department.Value ?? string.Empty;
                bool   bIsDisable = isDisable == true.ToString();
                //bool bIsPowerUser = isPowerUser == true.ToString();
                //bool bIsAdmin = isAdmin == true.ToString();
                try
                {
                    if (SCUtility.isEmpty(userID))  //A0.01
                    {
                        result = "User ID is empty!";
                    }
                    else if (SCUtility.isEmpty(userName))  //A0.01
                    {
                        result = "User name is empty!";
                    }
                    else if (SCUtility.isEmpty(userGrp))  //A0.01
                    {
                        result = "User Group is empty!";
                    }
                    else
                    {
                        Boolean createSuccess =
                            scApp.UserBLL.createUser(userID, userName, password, bIsDisable, userGrp, badgeNo, department); //A0.01
                        if (createSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "CREATE_FAILED";
                        }
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["UserControl/UserAccountUpdate"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userID    = Request.Query.userID.Value ?? Request.Form.userID.Value ?? string.Empty;
                string userName  = Request.Query.userName.Value ?? Request.Form.userName.Value ?? string.Empty;
                string password  = Request.Query.password.Value ?? Request.Form.password.Value ?? string.Empty;
                string isDisable = Request.Query.isDisable.Value ?? Request.Form.isDisable.Value ?? string.Empty;
                //string isPowerUser = Request.Query.isPowerUser.Value ?? Request.Form.isPowerUser.Value ?? string.Empty;
                string userGrp = Request.Query.userGrp.Value ?? Request.Form.userGrp.Value ?? string.Empty;
                string badgeNo = Request.Query.badgeNo.Value ?? Request.Form.badgeNo.Value ?? string.Empty;
                //string isAdmin = Request.Query.isAdmin.Value ?? Request.Form.isAdmin.Value ?? string.Empty;
                string department = Request.Query.department.Value ?? Request.Form.department.Value ?? string.Empty;
                bool   bIsDisable = isDisable == true.ToString();
                //bool bIsPowerUser = isPowerUser == true.ToString();
                //bool bIsAdmin = isAdmin == true.ToString();
                try
                {
                    if (SCUtility.isEmpty(userID))  //A0.01
                    {
                        result = "User ID is empty!";
                    }
                    else if (SCUtility.isEmpty(userName))  //A0.01
                    {
                        result = "User name is empty!";
                    }
                    else if (SCUtility.isEmpty(userGrp))  //A0.01
                    {
                        result = "User Group is empty!";
                    }
                    else
                    {
                        Boolean updateSuccess =
                            scApp.UserBLL.updateUser(userID, userName, password, bIsDisable, userGrp, badgeNo, department); //A0.01
                        if (updateSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "UPDATE_FAILED";
                        }
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["UserControl/UserAccountDelete"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userID = Request.Query.userID.Value ?? Request.Form.userID.Value ?? string.Empty;
                try
                {
                    Boolean deleteSuccess = scApp.UserBLL.deleteUser(userID);
                    if (deleteSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "DELETE_FAILED";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["UserControl/UserGroupAdd"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                string result     = string.Empty;
                string resuleJson = string.Empty;

                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resuleJson = reader.ReadToEnd();
                    }
                }
                var    fun_enable = JsonConvert.DeserializeObject <Dictionary <string, bool> >(resuleJson);
                string userGrp    = fun_enable.FirstOrDefault().Key;
                //string userGrp = Request.Query.userGrp.Value ?? Request.Form.userGrp.Value ?? string.Empty;
                //string funcCloseSystem = Request.Query.funcCloseSystem.Value ?? Request.Form.funcCloseSystem.Value ?? string.Empty;
                //string funcSystemControlMode = Request.Query.funcSystemControlMode.Value ?? Request.Form.funcSystemControlMode.Value ?? string.Empty;
                //string funcLogin = Request.Query.funcLogin.Value ?? Request.Form.funcLogin.Value ?? string.Empty;
                //string funcAccountManagement = Request.Query.funcAccountManagement.Value ?? Request.Form.funcAccountManagement.Value ?? string.Empty;
                //string funcVehicleManagement = Request.Query.funcVehicleManagement.Value ?? Request.Form.funcVehicleManagement.Value ?? string.Empty;
                //string funcTransferManagement = Request.Query.funcTransferManagement.Value ?? Request.Form.funcTransferManagement.Value ?? string.Empty;
                //string funcMTLMTSMaintenance = Request.Query.funcMTLMTSMaintenance.Value ?? Request.Form.funcMTLMTSMaintenance.Value ?? string.Empty;
                //string funcPortMaintenance = Request.Query.funcPortMaintenance.Value ?? Request.Form.funcPortMaintenance.Value ?? string.Empty;
                //string funcDebug = Request.Query.funcDebug.Value ?? Request.Form.funcDebug.Value ?? string.Empty;
                //string funcAdvancedSettings = Request.Query.funcAdvancedSettings.Value ?? Request.Form.funcAdvancedSettings.Value ?? string.Empty;

                //bool bfuncCloseSystem = funcCloseSystem == true.ToString();
                //bool bfuncSystemControlMode = funcSystemControlMode == true.ToString();
                //bool bfuncLogin = funcLogin == true.ToString();
                //bool bfuncAccountManagement = funcAccountManagement == true.ToString();
                //bool bfuncVehicleManagement = funcVehicleManagement == true.ToString();
                //bool bfuncTransferManagement = funcTransferManagement == true.ToString();
                //bool bfuncMTLMTSMaintenance = funcMTLMTSMaintenance == true.ToString();
                //bool bfuncPortMaintenance = funcPortMaintenance == true.ToString();
                //bool bfunDebug = funcDebug == true.ToString();
                //bool bfunAdvancedSettings = funcAdvancedSettings == true.ToString();

                try
                {
                    if (SCUtility.isEmpty(userGrp))
                    {
                        result = "User Group is empty!";
                    }
                    else
                    {
                        Boolean createSuccess = scApp.UserBLL.addUserGroup(userGrp);

                        if (createSuccess)
                        {
                            List <string> functionList = new List <string>();
                            foreach (var item in fun_enable)
                            {
                                if (item.Value == true)
                                {
                                    functionList.Add(item.Key);
                                }
                            }

                            //if (bfuncCloseSystem) functionList.Add(SCAppConstants.FUNC_CLOSE_SYSTEM);
                            //if (bfuncSystemControlMode) functionList.Add(SCAppConstants.FUNC_SYSTEM_CONCROL_MODE);
                            //if (bfuncLogin) functionList.Add(SCAppConstants.FUNC_LOGIN);
                            //if (bfuncAccountManagement) functionList.Add(SCAppConstants.FUNC_ACCOUNT_MANAGEMENT);
                            //if (bfuncVehicleManagement) functionList.Add(SCAppConstants.FUNC_VEHICLE_MANAGEMENT);
                            //if (bfuncTransferManagement) functionList.Add(SCAppConstants.FUNC_TRANSFER_MANAGEMENT);
                            //if (bfuncMTLMTSMaintenance) functionList.Add(SCAppConstants.FUNC_MTS_MTL_MAINTENANCE);
                            //if (bfuncPortMaintenance) functionList.Add(SCAppConstants.FUNC_PORT_MAINTENANCE);
                            //if (bfunDebug) functionList.Add(SCAppConstants.FUNC_DEBUG);
                            //if (bfunAdvancedSettings) functionList.Add(SCAppConstants.FUNC_ADVANCED_SETTINGS);

                            createSuccess = scApp.UserBLL.registerUserFunc(userGrp, functionList);
                            if (createSuccess)
                            {
                                result = "OK";
                            }
                            else
                            {
                                result = "Create user function failed.";
                            }
                        }
                        else
                        {
                            result = "Create user group failed.";
                        }
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["UserControl/UserGroupUpdate"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                string result     = string.Empty;
                string resuleJson = string.Empty;

                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resuleJson = reader.ReadToEnd();
                    }
                }

                var    fun_enable = JsonConvert.DeserializeObject <Dictionary <string, bool> >(resuleJson);
                string userGrp    = fun_enable.FirstOrDefault().Key;
                //string funcCloseSystem = Request.Query.funcCloseSystem.Value ?? Request.Form.funcCloseSystem.Value ?? string.Empty;
                //string funcSystemControlMode = Request.Query.funcSystemControlMode.Value ?? Request.Form.funcSystemControlMode.Value ?? string.Empty;
                //string funcLogin = Request.Query.funcLogin.Value ?? Request.Form.funcLogin.Value ?? string.Empty;
                //string funcAccountManagement = Request.Query.funcAccountManagement.Value ?? Request.Form.funcAccountManagement.Value ?? string.Empty;
                //string funcVehicleManagement = Request.Query.funcVehicleManagement.Value ?? Request.Form.funcVehicleManagement.Value ?? string.Empty;
                //string funcTransferManagement = Request.Query.funcTransferManagement.Value ?? Request.Form.funcTransferManagement.Value ?? string.Empty;
                //string funcMTLMTSMaintenance = Request.Query.funcMTLMTSMaintenance.Value ?? Request.Form.funcMTLMTSMaintenance.Value ?? string.Empty;
                //string funcPortMaintenance = Request.Query.funcPortMaintenance.Value ?? Request.Form.funcPortMaintenance.Value ?? string.Empty;
                //string funcDebug = Request.Query.funcDebug.Value ?? Request.Form.funcDebug.Value ?? string.Empty;
                //string funcAdvancedSettings = Request.Query.funcAdvancedSettings.Value ?? Request.Form.funcAdvancedSettings.Value ?? string.Empty;

                //bool bfuncCloseSystem = funcCloseSystem == true.ToString();
                //bool bfuncSystemControlMode = funcSystemControlMode == true.ToString();
                //bool bfuncLogin = funcLogin == true.ToString();
                //bool bfuncAccountManagement = funcAccountManagement == true.ToString();
                //bool bfuncVehicleManagement = funcVehicleManagement == true.ToString();
                //bool bfuncTransferManagement = funcTransferManagement == true.ToString();
                //bool bfuncMTLMTSMaintenance = funcMTLMTSMaintenance == true.ToString();
                //bool bfuncPortMaintenance = funcPortMaintenance == true.ToString();
                //bool bfunDebug = funcDebug == true.ToString();
                //bool bfunAdvancedSettings = funcAdvancedSettings == true.ToString();

                try
                {
                    if (SCUtility.isEmpty(userGrp))
                    {
                        result = "User Group is empty!";
                    }
                    else
                    {
                        List <string> functionList = new List <string>();
                        foreach (var item in fun_enable)
                        {
                            if (item.Value == true)
                            {
                                functionList.Add(item.Key);
                            }
                        }
                        //if (bfuncCloseSystem) functionList.Add(SCAppConstants.FUNC_CLOSE_SYSTEM);
                        //if (bfuncSystemControlMode) functionList.Add(SCAppConstants.FUNC_SYSTEM_CONCROL_MODE);
                        //if (bfuncLogin) functionList.Add(SCAppConstants.FUNC_LOGIN);
                        //if (bfuncAccountManagement) functionList.Add(SCAppConstants.FUNC_ACCOUNT_MANAGEMENT);
                        //if (bfuncVehicleManagement) functionList.Add(SCAppConstants.FUNC_VEHICLE_MANAGEMENT);
                        //if (bfuncTransferManagement) functionList.Add(SCAppConstants.FUNC_TRANSFER_MANAGEMENT);
                        //if (bfuncMTLMTSMaintenance) functionList.Add(SCAppConstants.FUNC_MTS_MTL_MAINTENANCE);
                        //if (bfuncPortMaintenance) functionList.Add(SCAppConstants.FUNC_PORT_MAINTENANCE);
                        //if (bfunDebug) functionList.Add(SCAppConstants.FUNC_DEBUG);
                        //if (bfunAdvancedSettings) functionList.Add(SCAppConstants.FUNC_ADVANCED_SETTINGS);

                        bool updateSuccess = false;
                        if (scApp.UserBLL.IsGrpExist(userGrp))
                        {
                            updateSuccess = scApp.UserBLL.registerUserFunc(userGrp, functionList);
                        }
                        //scApp.UserBLL.addUserGroup(userGrp);

                        if (updateSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "UPDATE_FAILED";
                        }
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["UserControl/UserGroupDelete"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                string userGrp = Request.Query.userGrp.Value ?? Request.Form.userGrp.Value ?? string.Empty;
                try
                {
                    Boolean deleteSuccess = scApp.UserBLL.deleteUserGroup(userGrp);
                    if (deleteSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "DELETE_FAILED";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
Esempio n. 7
0
        private void RegisterTransferManagementEvent()
        {
            Post["TransferManagement/MCSQueueSwitch"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                try
                {
                    string AutoAssign   = Request.Query.AutoAssign.Value ?? Request.Form.AutoAssign.Value ?? string.Empty;
                    bool   isAutoAssign = Convert.ToBoolean(AutoAssign);
                    scApp.getEQObjCacheManager().getLine().MCSCommandAutoAssign = isAutoAssign;
                    result = "OK";
                }
                catch (Exception ex)
                {
                    result = "MCS Queue Switch update failed with exception happened";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/CancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string result    = string.Empty;

                CMDCancelType cnacel_type = default(CMDCancelType);
                string        mcs_cmd_id  = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);

                    scApp.TransferService.Manual_DeleteCmd(mcs_cmd_id, "正式 UI");

                    UserOperationLog userOperationLog = new UserOperationLog()
                    {
                        Action     = "TransferCancelAbort",
                        ActionTime = DateTime.Now,
                        CommandID  = mcs_cmd_id,
                    };
                    SCUtility.UserOperationLog(userOperationLog);
                    //if (mcs_cmd == null)
                    //{
                    //    result = $"Can not find transfer command:[{mcs_cmd_id}].";
                    //}
                    //else
                    //{
                    //    if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                    //    {
                    //        cnacel_type = CMDCancelType.CmdCancel;
                    //        bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                    //        if (btemp)
                    //        {
                    //            result = "OK";
                    //        }
                    //        else
                    //        {
                    //            result = $"Transfer command:[{mcs_cmd_id}] cancel failed.";
                    //        }
                    //    }
                    //    else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                    //    {
                    //        cnacel_type = CMDCancelType.CmdAbort;
                    //        bool btemp = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, cnacel_type);
                    //        if (btemp)
                    //        {
                    //            result = "OK";
                    //        }
                    //        else
                    //        {
                    //            result = $"Transfer command:[{mcs_cmd_id}] adort failed.";
                    //        }
                    //    }
                    //    else
                    //    {
                    //        result = $"Command ID:{mcs_cmd.CMD_ID.Trim()} can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["TransferManagement/ForceFinish"] = (p) =>
            {
                var      scApp            = SCApplication.getInstance();
                bool     isSuccess        = true;
                string   result           = string.Empty;
                string   mcs_cmd_id       = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                AVEHICLE excute_cmd_of_vh = scApp.VehicleBLL.cache.getVehicleByMCSCmdID(mcs_cmd_id);
                ACMD_MCS mcs_cmd          = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                try
                {
                    if (excute_cmd_of_vh != null)
                    {
                        scApp.VehicleBLL.doTransferCommandFinish(excute_cmd_of_vh.VEHICLE_ID, excute_cmd_of_vh.OHTC_CMD, CompleteStatus.CmpStatusForceFinishByOp);
                        scApp.VIDBLL.initialVIDCommandInfo(excute_cmd_of_vh.VEHICLE_ID);
                    }
                    //scApp.CMDBLL.updateCMD_MCS_TranStatus2Complete(mcs_cmd.CMD_ID, E_TRAN_STATUS.Aborting);
                    scApp.ReportBLL.newReportTransferCommandNormalFinish(mcs_cmd, excute_cmd_of_vh, sc.Data.SECS.CSOT.SECSConst.CMD_Result_Unsuccessful, null);
                    result = "OK";
                }
                catch
                {
                    result = "ForceFinish failed.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferForceFinish",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/AssignVehicle"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.assignCommnadToVehicle(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Assign command to  vehicle failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferAssignVehicle",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
            Post["TransferManagement/ShiftCommand"] = (p) =>
            {
                var    scApp  = SCApplication.getInstance();
                string result = string.Empty;

                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                try
                {
                    ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    scApp.CMDBLL.commandShift(mcs_cmd_id, vh_id, out result);
                }
                catch (Exception ex)
                {
                    result = "Shift command failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferShiftCommand",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/ChangeStatus"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string sstatus    = Request.Query.status.Value ?? Request.Form.status.Value ?? string.Empty;
                try
                {
                    ACMD_MCS      mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    E_TRAN_STATUS status  = (E_TRAN_STATUS)Enum.Parse(typeof(E_TRAN_STATUS), sstatus, false);

                    if (mcs_cmd != null)
                    {
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_TranStatus(mcs_cmd_id, status);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update status failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update status failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferChangeStatus",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                //Todo by Mark

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/Priority"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string mcs_cmd_id = Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;
                string priority   = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;
                try
                {
                    ACMD_MCS mcs_cmd   = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                    int      iPriority = Convert.ToInt32(priority);
                    if (mcs_cmd != null)
                    {
                        //isSuccess = scApp.CMDBLL.updateCMD_MCS_PrioritySUM(mcs_cmd, iPriority);
                        isSuccess = scApp.CMDBLL.updateCMD_MCS_PortPriority(mcs_cmd.CMD_ID, iPriority);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Update priority failed.";
                        }
                    }
                    else
                    {
                        result = $"Can not find MCS Command[{mcs_cmd_id}].";
                    }
                }
                catch (Exception ex)
                {
                    result = "Update priority failed with exception happened.";
                }

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferPriority",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["TransferManagement/TransferCreate"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;

                int    Y      = DateTime.Now.Year % 100;
                string stDate = string.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}", Y, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

                string mcs_cmd_id = "MANAUL-" + stDate;//Request.Query.mcs_cmd.Value ?? Request.Form.mcs_cmd.Value ?? string.Empty;

                string priority = Request.Query.priority.Value ?? Request.Form.priority.Value ?? string.Empty;

                string box_id = Request.Query.box_id.Value ?? Request.Form.box_id.Value ?? string.Empty;
                string cst_id = Request.Query.cst_id.Value ?? Request.Form.cst_id.Value ?? string.Empty;
                string source = Request.Query.source.Value ?? Request.Form.source.Value ?? string.Empty;
                string dest   = Request.Query.dest.Value ?? Request.Form.dest.Value ?? string.Empty;
                string lot_id = Request.Query.lot_id.Value ?? Request.Form.lot_id.Value ?? string.Empty;
                result = scApp.TransferService.Manual_InsertCmd(source, dest, 5);

                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "TransferCreate",
                    ActionTime = DateTime.Now,
                    CommandID  = mcs_cmd_id,
                    Source     = source,
                    Dest       = dest,
                    BOXID      = box_id,
                };
                SCUtility.UserOperationLog(userOperationLog);

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Get["TransferManagement/TransferCheck/AGVStation/{AGVStationID}"] = (p) =>
            {
                SCApplication scApp = SCApplication.getInstance();
                //string queue_count = 0;
                scApp.TransferService.swapTriggerWaitin = false;
                string agv_station_id = p.AGVStationID;
                string excute_count   = Request.Query.unfinishCmdCount.Value ?? Request.Form.unfinishCmdCount.Value ?? string.Empty;
                string is_emergency   = Request.Query.isEmergency.Value ?? Request.Form.isEmergency.Value ?? string.Empty;
                bool   emergency      = false;
                if (is_emergency == "true")
                {
                    emergency = true;
                }
                else if (is_emergency == "false")
                {
                    emergency = false;
                }
                // Change the default return from false to true.
                // 因為目前回復NG時會產生AGV走行命令回到AGV Station,但目前預設值設定為false 因避免exception情形(AGVC Cmd == 0 時回復True 不會停止觸發OHBC)
                bool is_ok = false;
                //todo 執行確認能否讓AGVC開始進行該AGV Station進貨的流程
                bool check_method = scApp.TransferService.oneInoneOutMethodUse;
                if (check_method)
                {
                    is_ok = scApp.TransferService.CanExcuteUnloadTransferAGVStationFromAGVC_OneInOneOut(agv_station_id.Trim(), Int32.Parse(excute_count), emergency);
                }
                else
                {
                    is_ok = scApp.TransferService.CanExcuteUnloadTransferAGVStationFromAGVC(agv_station_id.Trim(), Int32.Parse(excute_count), emergency);
                }
                var response = (Response)(is_ok ? "OK" : "NG");
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["TransferManagement/TransferCheck/Swap/AGVStation/{AGVStationID}"] = (p) =>
            {
                SCApplication scApp = SCApplication.getInstance();
                //string queue_count = 0;
                scApp.TransferService.swapTriggerWaitin = true;
                string agv_station_id = p.AGVStationID;
                string excute_count   = Request.Query.unfinishCmdCount.Value ?? Request.Form.unfinishCmdCount.Value ?? string.Empty;
                string is_emergency   = Request.Query.isEmergency.Value ?? Request.Form.isEmergency.Value ?? string.Empty;
                bool   emergency      = false;
                is_emergency = is_emergency.ToUpper();
                if (is_emergency.Contains("T"))
                {
                    emergency = true;
                }
                else if (is_emergency.Contains("F"))
                {
                    emergency = false;
                }
                // Change the default return from false to true.
                // 因為目前回復NG時會產生AGV走行命令回到AGV Station,但目前預設值設定為false 因避免exception情形(AGVC Cmd == 0 時回復True 不會停止觸發OHBC)
                bool is_ok       = false;
                bool is_more_out = false;

                //todo 執行確認能否讓AGVC開始進行該AGV Station進貨的流程
                (is_ok, is_more_out) = scApp.TransferService.CanExcuteUnloadTransferAGVStationFromAGVC_Swap(agv_station_id.Trim(), Int32.Parse(excute_count), emergency);

                string check_result            = is_ok ? "OK" : "NG";
                E_AGVStationTranMode tran_mode = is_more_out ? E_AGVStationTranMode.MoreOut : E_AGVStationTranMode.MoreIn;

                int s_tran_mode = (int)tran_mode;
                //var response = (Response)(is_ok ? "OK" : "NG");
                var response = (Response)($"{check_result},{s_tran_mode}");
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["TransferManagement/PreOpenAGVStationCover/AGVStationPorts/{AGVStationPortID}"] = (p) =>
            {
                SCApplication scApp = SCApplication.getInstance();
                string        agv_station_port_id = p.AGVStationPortID;

                bool is_ok = true;
                is_ok = scApp.TransferService.SetAGV_PortOpenBOX(agv_station_port_id, "TransferManagement");

                var response = (Response)(is_ok ? "OK" : "NG");
                response.ContentType = restfulContentType;

                return(response);
            };
        }