Beispiel #1
0
        /// <summary>
        /// NoChanges则继续,HaveChangd则重新计时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetLightTimeBtn_Click(object sender, RoutedEventArgs e)
        {
            //WrtLightCd(string rCount, string yCount, string gCount)
            tempTextRedAfter    = Lights.FetchNum(redCount.Text).ToString();
            tempTextYellowAfter = Lights.FetchNum(yellowCount.Text).ToString();
            tempTextGreenAfter  = Lights.FetchNum(greenCount.Text).ToString();

            bool redCountChanged     = Lights.IsTextChanged(tempTextRedBefore, tempTextRedAfter);
            bool yellowCountChangded = Lights.IsTextChanged(tempTextYellowBefore, tempTextYellowAfter);
            bool greenCountChanged   = Lights.IsTextChanged(tempTextGreenBefore, tempTextGreenAfter);

            //把更改后的内容保存到App.config中
            string rCount = Lights.IsValueChanged(redCountChanged, tempTextRedAfter);
            string yCount = Lights.IsValueChanged(yellowCountChangded, tempTextYellowAfter);
            string gCount = Lights.IsValueChanged(greenCountChanged, tempTextGreenAfter);

            Lights.WrtLightCd(rCount, yCount, gCount);


            if (redCountChanged || yellowCountChangded || greenCountChanged)
            {
                Lights.StopTimer();
                ReIniParamThenRestart();
            }
            else
            {
                Lights.ProceedTimer();
            }
            SetLightTimeBtn.Foreground = new SolidColorBrush(Lights.Green);
        }
Beispiel #2
0
 /// <summary>
 /// UnitTimer.Tick事件调用的方法
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void UnitCycleTimer_Tick(object sender, EventArgs e)
 {
     //为UnitTimerCycle()赋值
     Lights.LightsUp(chooseLightColor.SelectedIndex);
     UnitTimerCycle(Lights.textFontColor, Lights.rLColor, Lights.yLColor, Lights.gLColor);
     halfSencondTimerTb.Text = "unitTick次数:" + (++unitTimerCount) + ";";
 }
Beispiel #3
0
        /// <summary>
        /// 初始化交通灯(红、黄、绿)各自的倒计时时间(firstLightRuntime\secondLightRuntime\thirdLightRuntime)
        /// </summary>
        private void IniPerLightRunTime(int selectedIndex)
        {
            string rName = redCount.Name;
            string yName = yellowCount.Name;
            string gName = greenCount.Name;

            Lights.IniPerLightRunTime(selectedIndex, rName, yName, gName);
        }
Beispiel #4
0
 /// <summary>
 /// MainTimer.Tick事件调用的方法
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MainCycleTimer_Tick(object sender, EventArgs e)
 {
     IniPerLightRunTime(chooseLightColor.SelectedIndex); //交通灯 三个灯的倒计时时间
     Lights.IniParamsInMainTimer();
     Lights.TrafficLightsRuntime();                      //初始化MainTimer.Interval
     Lights.IniLightsUpSequenceColor(chooseLightColor.SelectedIndex);
     mainTimerTb.Text = "mainTick次数:" + (++mainTimerCount).ToString() + ";" + "mainInterval:" + Lights.trafficLightsTime;
 }
Beispiel #5
0
        void RunTrafficLight()
        {
            ConfigValueToTbx();
            IniPerLightRunTime(chooseLightColor.SelectedIndex);//***初始化Interval;如果没有此行,就获取不到每个交通灯对应的倒计时时间<==>Interval=0;***
            Lights.mainCycleTimer.Start();
            Lights.IniParamsInMainTimer();
            //TrafficLightsTime.mainCycleTimer.Tick += MainCycleTimer_Tick;
            //主计时器要考虑副计时器的延时时间不?1000ms的出现是因为计时器的延迟(halfSecondCycleTimer每次Tick会有10ms-20ms的延迟)
            //mainCycleTimer.Interval = TimeSpan.FromMilliseconds((TrafficLightsTime.firstLightRuntime + TrafficLightsTime.secondLightRuntime + TrafficLightsTime.thirdLightRuntime) * 1000 + 1000);
            Lights.mainCycleTimer.Interval = TimeSpan.FromMilliseconds(Lights.trafficLightsTime * 1000 + 1000);

            Lights.unitCycleTimer.Start();
            Lights.unitCycleTimer.Interval = TimeSpan.FromMilliseconds(500);//0.5s=500ms
        }
Beispiel #6
0
        private void chooseLightColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Lights.StopTimer();
            ComboBoxItem cbItem = sender as ComboBoxItem;

            if (cbItem != null)
            {
                LightsColor(cbItem.Content.ToString());//设置灯和文本的颜色
            }
            if (!firstClick)
            {
                ReIniParamThenRestart();
            }
        }
Beispiel #7
0
        private void AddTimeBtn_Click(object sender, RoutedEventArgs e)
        {
            Lights.StopTimer();
            int addTime;

            //没有不能转换为数字、输入数值大小等问题
            if (AddTimeTbx.Text == null)
            {
                addTime = 0;
            }
            else
            {
                addTime = Convert.ToInt32(AddTimeTbx.Text);
            }
            Lights.GetAddTimeParamsValue(addTime);
            SetXStatusLables();
        }
Beispiel #8
0
        //private void RestartTimer()
        //{
        //    Lights.StopTimer();
        //    ReInitializeParamThenRestart();
        //}
        /// <summary>
        /// 重启两个计时器(注意Timer.Start()的顺序)
        /// </summary>
        private void ReIniParamThenRestart()
        {
            //循环之初要处理的数据(MainTimer_Tick)
            IniPerLightRunTime(chooseLightColor.SelectedIndex);//交通灯 三个灯的倒计时时间
            Lights.IniParamsInMainTimer();
            Lights.IniLightsUpSequenceColor(chooseLightColor.SelectedIndex);

            //每个循环要做的事情(UnitTimer_Tick)
            Lights.LightsUp(chooseLightColor.SelectedIndex);
            countdownCurrenLightupTbk.Text       = Lights.countdownToUI.ToString();
            countdownLightsTbk.Text              = (Lights.trafficLightsTime2 + 1).ToString();
            countdownCurrenLightupTbk.Foreground = new SolidColorBrush(Lights.textFontColor);
            redLight.Fill    = new SolidColorBrush(Lights.rLColor);
            yellowLight.Fill = new SolidColorBrush(Lights.yLColor);
            greenLight.Fill  = new SolidColorBrush(Lights.gLColor);

            //启动计时器,第一个Tick发生在Interval时间之后
            Lights.ProceedTimer();
        }
        public void ToggleSignal()
        {
            var signals = typeof(Lights).GetEnumValues();

            this.signal = (Lights)signals.GetValue((int)(signal + 1) % signals.Length);
        }
Beispiel #10
0
 /// <summary>
 /// 给三个用来设置红绿灯运行时间的TextBox.Text赋值
 /// </summary>
 private void ConfigValueToTbx()
 {
     redCount.Text    = Lights.RdLightCd(redCount.Name).ToString();
     yellowCount.Text = Lights.RdLightCd(yellowCount.Name).ToString();
     greenCount.Text  = Lights.RdLightCd(greenCount.Name).ToString();
 }
Beispiel #11
0
        /// <summary>
        /// Label:"周期""afterCurStatusColor.Tostring()""beforeCurStatusColor.ToString()""xStatusColor.ToString()"
        /// </summary>
        private void SetXStatusLables()
        {
            //***beforeCurStatusTime----xCurStatusTime-----afterCurStatusTime***//
            int v   = Lights.validTime;
            int x   = Lights.xCurStatusTimeLeft;
            int a   = Lights.afterXStatusTime;
            int b   = Lights.beforeXStatusTime;
            int tL1 = Lights.trafficLightsTime1;

            LblNum4.Content     = "当前状态:剩余" + Lights.calculate(x) + "秒";
            LblContent4.Content = Lights.ColorToTextString(Lights.xCurStatusColor);

            if (Lights.addTime >= tL1)
            {
                LblContent3.Content = "周期";
                LblNum3.Content     = Lights.nCycle.ToString("000") + "个";

                //addTime = addTimeMW * 2;
                //nCycle = addTime / trafficLightsTime * 2;
                //validTime = addTime % trafficLightsTime * 2;

                LblContent0.Content = Lights.ColorToTextString(Lights.afterXStatusColor);
                LblContent1.Content = Lights.ColorToTextString(Lights.beforeXStatusColor);
                LblContent2.Content = Lights.ColorToTextString(Lights.xCurStatusColor);

                if ((v >= 0) && (v <= a))
                {
                    LblNum0.Content = Lights.calculate(v).ToString("000") + "秒";
                    LblNum1.Content = "000秒";
                    LblNum2.Content = "000秒";
                }
                else if ((v > a) && (v <= (a + b)))
                {
                    LblNum0.Content = Lights.calculate(a).ToString("000") + "秒";
                    LblNum1.Content = Lights.calculate(v - a).ToString("000") + "秒";
                    LblNum2.Content = "000秒";
                }
                else if ((v > (a + b)) && (v < tL1))
                {
                    LblNum0.Content = Lights.calculate(a).ToString("000") + "秒";
                    LblNum1.Content = Lights.calculate(b).ToString("000") + "秒";
                    LblNum2.Content = Lights.calculate(tL1 - a - b).ToString("000") + "秒";
                }
            }
            else
            {
                //Lbl0.Content = "周期";
                //LblNum0.Content = TrafficLightsTime.nCycle.ToString("000") + "个";
                //addTime = addTimeMW * 2;
                //nCycle = addTime / trafficLightsTime * 2;
                //validTime = addTime % trafficLightsTime * 2;

                LblContent0.Content = Lights.ColorToTextString(Lights.afterXStatusColor);
                LblContent1.Content = Lights.ColorToTextString(Lights.beforeXStatusColor);
                LblContent2.Content = Lights.ColorToTextString(Lights.xCurStatusColor);
                if ((v >= 0) && (v <= a))
                {
                    LblNum0.Content = Lights.calculate(v).ToString("000") + "秒";
                    LblNum1.Content = "000" + "秒";
                    LblNum2.Content = "000" + "秒";
                }
                else if ((v > a) && (v <= (a + b)))
                {
                    LblNum0.Content = Lights.calculate(a).ToString("000") + "秒";
                    LblNum1.Content = (v - a).ToString("000") + "秒";
                    LblNum2.Content = "000" + "秒";
                }
                else if ((v > (a + b)) && (v < tL1))
                {
                    LblNum0.Content = Lights.calculate(a).ToString("000") + "秒";
                    LblNum1.Content = Lights.calculate(b).ToString("000") + "秒";
                    LblNum2.Content = Lights.calculate(tL1 - a - b).ToString("000") + "秒";
                }
            }
        }
Beispiel #12
0
 private void btnDisableTimer_Click(object sender, RoutedEventArgs e)
 {
     Lights.StopTimer();
 }
        public void ChangeLight()
        {
            var previousLight = (int)this.lights;

            this.lights = (Lights)((previousLight + 1) % Enum.GetNames(typeof(Lights)).Length);
        }
 public TrafficLight(string lights)
 {
     this.lights = (Lights)Enum.Parse(typeof(Lights), lights);
 }