Ejemplo n.º 1
0
        private Train CreateTrain(Station startStation)
        {
            var driver = new Worker
            {
                FirstName = "Андрей",
                MiddleName = "Андрей",
                LastName = "Андрей",
                Salary = 400m,
                LengthOfService = 1
            };

            var cond1 = new Worker
            {
                FirstName = "cond1",
                MiddleName = "cond1",
                LastName = "cond1",
                Salary = 200,
                LengthOfService = 1
            };
            var cond2 = new Worker
            {
                FirstName = "cond2",
                MiddleName = "cond2",
                LastName = "cond2",
                Salary = 200,
                LengthOfService = 1
            };
            var cond3 = new Worker
            {
                FirstName = "cond3",
                MiddleName = "cond3",
                LastName = "cond3",
                Salary = 200,
                LengthOfService = 1
            };

            var train = new Train
            {
                Name = "First Train",
                CurrentStation = startStation,
                Driver = driver,
                Velocity = 60
            };

            var wagon1 = new Wagon {MaxPassengerCount = 3, Conductor = cond1};
            var wagon2 = new Wagon { MaxPassengerCount = 3, Conductor = cond2 };
            var wagon3 = new Wagon { MaxPassengerCount = 3, Conductor = cond3 };

            train.Wagons.Add(wagon1); train.Wagons.Add(wagon2); train.Wagons.Add(wagon3);

            return train;
        }
Ejemplo n.º 2
0
        private void buttonAddTrain_Click(object sender, EventArgs e)
        {
            var name = textBoxNewTrainName.Text;
            if (String.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("Введите название поезда");
                return;
            }

            int maxWagons, velocity;
            try
            {
                maxWagons = Int32.Parse(textBoxMaxWagonCount.Text);
                velocity = Int32.Parse(textBoxVelocity.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Неверные данные");
                return;
            }

            var driver = comboBoxFreeDrivers.SelectedItem as Worker;
            if (driver == null) return;

            var startStation = comboBoxStartTrainStations.SelectedItem as Station;
            if (startStation == null) return;

            var train = new Train
            {
                Name = name,
                MaxWagonCount = maxWagons,
                Velocity = velocity,
                Driver = driver,
                CurrentStation = startStation
            };

            Server.Context.Trains.Add(train);
            Server.Context.SaveChanges();
        }