Exemplo n.º 1
0
        public SignalProp getCurSigProp()
        {
            SignalProp   prop = null;
            String       sql  = " SELECT s.lampId, s.signalName, s.type, s.state, c.state as specState, direction, dir_to, s.ip FROM cursignal c LEFT JOIN signal s ON c.lampId=s.lampId AND c.type=1 ";
            MySqlCommand cmd  = new MySql.Data.MySqlClient.MySqlCommand(sql, myConn);

            System.Data.Common.DbDataReader reader = cmd.ExecuteReader();
            try
            {
                if (reader.Read())
                {
                    prop            = new SignalProp();
                    prop.SignalID   = reader.GetString(0).ToUpper();
                    prop.SignalName = DBStringToNormal(reader.GetString(1));
                    prop.Type       = reader.IsDBNull(2)? (byte)0 : (byte)reader.GetInt16(2);
                    prop.State      = reader.GetString(3);
                    prop.SpecState  = reader.IsDBNull(4) ? (byte)0 : (byte)reader.GetInt16(4);
                    prop.DirFrom    = reader.IsDBNull(5) ? (byte)0 : (byte)reader.GetInt16(5);
                    prop.DirTo      = reader.IsDBNull(6) ? (byte)0 : (byte)reader.GetInt16(6);
                    prop.Ip         = reader.GetString(7);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                reader.Close();
                Trace.TraceError("get cur signal prop " + e.StackTrace);
            }

            return(prop);
        }
Exemplo n.º 2
0
        private void tvSignalList_DoubleClick(object sender, EventArgs e)
        {
            string     selStr = tvSignalList.SelectedNode.Text;
            SignalProp prop   = SignalFactory.getSigPropByName(selStr, sigList);

            timerGetCurSig.Enabled = false;

            if (null != prop)
            {
                tlog(prop.ToString());
                curSignal = SignalFactory.buildController(prop);
                tlog(prop.ToString());
                showMap(prop.SignalID);
                showSigInfo(prop);
                rbManSpec.Checked = true;

                if (curSignal.connect())
                {
                    timerGetCurSig.Enabled = true;
                }
                else
                {
                    lblSignalName.Text = "信号机:" + prop.SignalName + " 连接失败";
                }
            }
            else
            {
                lblSignalName.Text = "未选中信号机";
            }
        }
Exemplo n.º 3
0
 private void showSigInfo(SignalProp prop)
 {
     lblBaseSigName.Text = prop.SignalName;
     lblBaseIP.Text      = prop.Ip;
     lblBaseType.Text    = CommonUtils.SigType[prop.Type];
     lblBaseState.Text   = prop.State;
 }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        private void dealWithSigProp(SignalProp prop)
        {
            if (!(null == prop && // 空值
                  curSigProp.SignalID.Equals(prop.SignalID) &&    // 信号机没变
                  curSigProp.State.Equals(prop.State) &&    // 且信号机状态没变
                  !FResize))         // 且窗口没变化
            {
                FResize = false;
                Trace.WriteLine(" deal with signal: " + prop.SignalID);
                if (null != prop.State && !"".Equals(prop.State))
                {
                    showState(prop);
                }

                curSigProp = prop;
                //curSigProp.SignalID = prop.SignalID;
                //curSigProp.State = prop.State;

                lblSignalName.Text = "信号机: " + prop.SignalName;
                //Trace.WriteLine(prop.ToString());
            }
        }
Exemplo n.º 6
0
        public List <SignalProp> getSignalList()
        {
            List <SignalProp> list = new List <SignalProp>();

            String       sql = " SELECT lampId, signalName, type, ip  FROM signal WHERE type IN (1, 4, 5) ";
            MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, myConn);

            System.Data.Common.DbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                SignalProp prop = new SignalProp();

                prop.SignalID   = reader.GetString(0).Trim().ToUpper(); //.Replace('-', '_')
                prop.SignalName = DBStringToNormal(reader.GetString(1).Trim());
                prop.Type       = reader.IsDBNull(2) ? (byte)1 : (byte)reader.GetInt32(2);
                prop.Ip         = reader.IsDBNull(3) ? "" : reader.GetString(3).Trim();

                list.Add(prop);
            }
            reader.Close();

            return(list);
        }
Exemplo n.º 7
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);
        }