Пример #1
0
        private void showState(SignalProp prop)
        {
            if (null == prop || prop.SignalID.Equals(""))
            {
                return;
            }

            String signal = prop.SignalID;

            if (null == curSignal || !signal.Equals(curSignal.Prop.SignalID.ToUpper()))
            {
                showMap(signal);
            }

            prop = SignalFactory.getSigProp(signal, sigList);

            int idx = 0;

            Trace.WriteLine(" showState: " + prop.ToString());

            try
            {
                // 东/南/西/北
                for (int i = 0; i < 4; i++)
                {
                    //直/左/右/人
                    for (int j = 0; j < 4; j++)
                    {
                        idx = i * 4 + j + 1;
                        string     str = "pb" + idx;
                        PictureBox pb  = (PictureBox)getCtrlByName(str);
                        //if (pb == null)
                        //    continue;

                        if (pb != null)
                        {
                            if (idx > prop.State.Length)
                            {
                                continue;
                            }

                            string c = prop.State.Substring(idx - 1, 1);
                            byte   s = byte.Parse(c);
                            Point  p = prop.Pos[idx - 1];
                            // Trace.WriteLine("  point: " + p.ToString() + " ang: " + prop.Angle[i]);
                            showAState(pb, p, prop.Angle[i], idx, s);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("showstate error: " + ex.StackTrace);
            }
        }
Пример #2
0
        /// <summary>
        /// 定时获取当前信号机状态,并展示在界面上
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (specPoly == 1)
            {// 自动特勤,从数据库中取当前信号机
                if (signalDao.getState() == ConnectionState.Open)
                {
                    FProp = signalDao.getCurSigProp();
                    String state = FProp.State;
                    FProp       = SignalFactory.getSigProp(FProp.SignalID, sigList);
                    FProp.State = state;

                    if (null == FProp)
                    {
                        return;
                    }

                    if (null == curSignal || !FProp.SignalID.Equals(curSignal.Prop.SignalID))
                    {
                        curSignal = SignalFactory.buildController(FProp);
                    }

                    curSignal.Prop = FProp;
                }
                else
                {
                    timerGetCurSig.Enabled = false;
                    showPBs(false);

                    lblSignalName.Text = "数据库未连接!";
                    return;
                }
            }
            else
            {//手动特勤,从左侧列表中取当前双击的信号机
                if (null == curSignal)
                {
                    timerGetCurSig.Enabled = false;
                    showPBs(false);
                    return;
                }

                if (curSignal.updateState())
                {
                    FProp = curSignal.Prop;
                    showSigInfo(FProp);
                    // lblBaseState.Text = FProp.State;
                }
                else
                {
                    // 如果更新状态失败,则说明信号机状态异常,则停掉定时器,避免程序挂死
                    timerGetCurSig.Enabled = false;
                    lblSignalName.Text     = "获取信号机状态失败";
                    showPBs(false);
                    return;
                }

                //listBox1.Items.Insert(0, null==curSignal.Prop.State?"get state error": curSignal.Prop.State);
            }

            // 处理显示
            showPBs(true);
            showSigInfo(FProp);
            dealWithSigProp(FProp);
        }