Exemplo n.º 1
0
        public bool doChangeHostMode(string host_mode, out string result)
        {
            bool isSuccess = true;

            result = string.Empty;
            try
            {
                if (isSuccess)
                {
                    using (TransactionScope tx = SCUtility.getTransactionScope())
                    {
                        using (DBConnection_EF con = DBConnection_EF.GetUContext())
                        {
                            if (host_mode == SCAppConstants.LineHostControlState.HostControlState.On_Line_Remote.ToString())
                            {
                                if (!scApp.LineService.canOnlineWithHost())
                                {
                                    //MessageBox.Show("Has vh not ready");
                                    //回報當無法連線
                                    result = "Has vh not ready";
                                }
                                else if (scApp.getEQObjCacheManager().getLine().Host_Control_State == SCAppConstants.LineHostControlState.HostControlState.On_Line_Remote)
                                {
                                    //MessageBox.Show("On line ready");
                                    result = "OnlineRemote ready";
                                }
                                else
                                {
                                    line.resetOnlieCheckItem();
                                    Task.Run(() => scApp.LineService.OnlineWithHostOp());
                                    result = "OK";
                                }
                                //isSuccess = scApp.PortStationBLL.OperateDB.updatePriority(portID, priority);
                                //if (isSuccess)
                                //{
                                tx.Complete();
                                //    scApp.PortStationBLL.OperateCatch.updatePriority(portID, priority);
                                //}
                            }
                            else if (host_mode == SCAppConstants.LineHostControlState.HostControlState.On_Line_Local.ToString())
                            {
                                if (!scApp.LineService.canOnlineWithHost())
                                {
                                    //MessageBox.Show("Has vh not ready");
                                    //回報當無法連線
                                    result = "Has vh not ready";
                                }
                                else if (scApp.getEQObjCacheManager().getLine().Host_Control_State == SCAppConstants.LineHostControlState.HostControlState.On_Line_Local)
                                {
                                    //MessageBox.Show("On line ready");
                                    result = "OnlineLocal ready";
                                }
                                else
                                {
                                    line.resetOnlieCheckItem();
                                    Task.Run(() => scApp.LineService.OnlineLocalWithHostOp());
                                    result = "OK";
                                }
                                //isSuccess = scApp.PortStationBLL.OperateDB.updatePriority(portID, priority);
                                //if (isSuccess)
                                //{
                                tx.Complete();
                                //    scApp.PortStationBLL.OperateCatch.updatePriority(portID, priority);
                                //}
                            }
                            else
                            {
                                if (scApp.getEQObjCacheManager().getLine().SCStats != TSCState.PAUSED)
                                {
                                    //MessageBox.Show("Please change tsc state to pause first.");
                                    result = "Please change TSC Status to pause first.";
                                }
                                else if (scApp.getEQObjCacheManager().getLine().Host_Control_State == SCAppConstants.LineHostControlState.HostControlState.EQ_Off_line)
                                {
                                    //MessageBox.Show("Current is off line");
                                    result = "Current is off line";
                                }
                                else
                                {
                                    line.resetOnlieCheckItem();
                                    Task.Run(() => scApp.LineService.OfflineWithHostByOp());
                                    result = "OK";
                                }
                                //isSuccess = scApp.PortStationBLL.OperateDB.updatePriority(portID, priority);
                                //if (isSuccess)
                                //{
                                tx.Complete();
                                //    scApp.PortStationBLL.OperateCatch.updatePriority(portID, priority);
                                //}
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isSuccess = false;
                logger.Error(ex, "Execption:");
            }
            return(isSuccess);
        }