Beispiel #1
0
        /* Handler for Done Button click */
        private void Done_Click(object sender, EventArgs e)
        {
            SignalConsole.Text = "";
            GetInputs();

            TimeElapsedLabel.Text  = "";
            ExpectedTimeLabel.Text = "";
            ProgressBar.Value      = 0;

            if (input == true)
            {
                if (m < 1 || n < 1 || gap < 1 || vM <= 0 || vR <= 0 || sD <= 0)
                {
                    Console.Beep();
                    SignalConsole.AppendText("\r\nError! : Please enter possible values in input.");
                    Start.Enabled = false;
                }

                if (vM < vR)
                {
                    Console.Beep();
                    SignalConsole.AppendText("\r\nError! : Maximum Speed should be bigger than Restricted Speed.");
                    Start.Enabled = false;
                }

                else
                {
                    Start.Enabled = true;
                    SignalConsole.AppendText("\r\nPress Start to start the Simulation.");
                }
            }

            else
            {
                Console.Beep();
                Start.Enabled = false;
            }
        }
Beispiel #2
0
        /* Takes inputs from the user */
        public void GetInputs()
        {
            input = true;

            try
            {
                m = Int32.Parse(TrainTextBox.Text);
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the number of trains in the correct format.");
                input = false;
            }

            try
            {
                n = Int32.Parse(SignalTextBox.Text);
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\n\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the number of signals in the correct format.");
                input = false;
            }

            try
            {
                if (Int32.Parse(GapTextBox1.Text) < 0 || Int32.Parse(GapTextBox2.Text) < 0 || Int32.Parse(GapTextBox3.Text) < 0)
                {
                    input = false;
                    SignalConsole.AppendText("\r\n\r\n Error! : Please enter possible values in Gap between Trains.");
                }
                else
                {
                    gap = (Int32.Parse(GapTextBox1.Text) * 3600) + (Int32.Parse(GapTextBox2.Text) * 60) + (Int32.Parse(GapTextBox3.Text));
                }
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\n\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the gap between trains in the correct format.");
                input = false;
            }

            try
            {
                vM = Double.Parse(MaxSpeedTextBox.Text);
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\n\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the maximum speed in the correct format.");
                input = false;
            }

            try
            {
                vR = Double.Parse(ResSpeedTextBox.Text);
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\n\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the restricted speed in the correct format.");
                input = false;
            }

            try
            {
                sD = Double.Parse(GapSignalsTextBox.Text);
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\n\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the gap between signals in the correct format.");
                input = false;
            }

            try
            {
                if (TimerComboBox.Text == "1 sec")
                {
                    intTimer   = 1000;
                    speedTimer = 1;
                }

                if (TimerComboBox.Text == "2 sec")
                {
                    intTimer   = 500;
                    speedTimer = 2;
                }

                if (TimerComboBox.Text == "5 sec")
                {
                    intTimer   = 200;
                    speedTimer = 5;
                }

                if (TimerComboBox.Text == "10 sec")
                {
                    intTimer   = 100;
                    speedTimer = 10;
                }

                if (TimerComboBox.Text == "1 min")
                {
                    intTimer   = 17;
                    speedTimer = 60;
                }
            }
            catch (Exception e)
            {
                SignalConsole.AppendText("\r\n\r\nError! : " + e.Message);
                SignalConsole.AppendText("\r\nPlease enter the timer in the correct format.");
                input = false;
            }
        }