示例#1
0
        private void ButtonClickEdit(object sender, RoutedEventArgs e)
        {
            Helicopter helicopter = helicoptersList.SelectedItem as Helicopter;

            if (helicopter != null)
            {
                helicopter.Model = ModelTextBox.Text;
                if (LengthTextBox.Text != String.Empty)
                {
                    helicopter.Length = int.Parse(LengthTextBox.Text);
                }
                if (HeightTextBox.Text != String.Empty)
                {
                    helicopter.Height = int.Parse(HeightTextBox.Text);
                }
                if (CarryingСapacityTextBox.Text != String.Empty)
                {
                    helicopter.CarryingCapacity = int.Parse(CarryingСapacityTextBox.Text);
                }
                if (EnginePowerTextBox.Text != String.Empty)
                {
                    helicopter.EnginePower = int.Parse(EnginePowerTextBox.Text);
                }
                helicoptersList.Items.Refresh();
            }
        }
示例#2
0
        private void ButtonClickDelete(object sender, RoutedEventArgs e)
        {
            Helicopter helicopter = helicoptersList.SelectedItem as Helicopter;

            if (helicopter != null)
            {
                Helicopters.Remove(helicopter);
                helicoptersList.SelectedItem = null;
            }
        }
示例#3
0
        private void helicoptersList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Helicopter helicopter = helicoptersList.SelectedItem as Helicopter;

            if (helicopter != null)
            {
                ModelTextBox.Text            = helicopter.Model;
                LengthTextBox.Text           = helicopter.Length.ToString();
                HeightTextBox.Text           = helicopter.Height.ToString();
                CarryingСapacityTextBox.Text = helicopter.CarryingCapacity.ToString();
                EnginePowerTextBox.Text      = helicopter.EnginePower.ToString();
            }
        }
示例#4
0
        public MainWindow()
        {
            Helicopter hel = new Helicopter();

            this.DataContext = hel;

            InitializeComponent();

            Helicopters = new ObservableCollection <Helicopter>
            {
                new Helicopter {
                    Model = "Apache", Length = 10, Height = 7, CarryingCapacity = 5, EnginePower = 1400
                },
                new Helicopter {
                    Model = "МИ-6", Length = 33, Height = 8, CarryingCapacity = 10, EnginePower = 8000
                },
            };

            helicoptersList.ItemsSource = Helicopters; // С помощью атрибута ItemsSource задаем привязку к свойству Helicopters
        }
示例#5
0
        private void ButtonClickAdd(object sender, RoutedEventArgs e)
        {
            Helicopter helicopter = new Helicopter();

            //while(true)
            //{
            if (string.IsNullOrEmpty(ModelTextBox.Text))
            {
                MessageBox.Show("Model can't be empty");
            }
            else
            {
                helicopter.Model = ModelTextBox.Text;
            }

            if (LengthTextBox.Text != String.Empty)
            {
                if (int.Parse(LengthTextBox.Text) < 0 && int.Parse(LengthTextBox.Text) > 50)
                {
                    MessageBox.Show("Length can't be less than 0 and more than 50");
                }
                else
                {
                    helicopter.Length = int.Parse(LengthTextBox.Text);
                }
            }

            if (EnginePowerTextBox.Text != String.Empty)
            {
                if (int.Parse(HeightTextBox.Text) < 0 && int.Parse(HeightTextBox.Text) > 20)
                {
                    MessageBox.Show("Height can't be less than 0 and more than 20");
                }
                else
                if (EnginePowerTextBox.Text != String.Empty)
                {
                    helicopter.Height = int.Parse(HeightTextBox.Text);
                }
            }


            if (EnginePowerTextBox.Text != String.Empty)
            {
                if (int.Parse(CarryingСapacityTextBox.Text) < 0 && int.Parse(CarryingСapacityTextBox.Text) > 30)
                {
                    //if (EnginePowerTextBox.Text != String.Empty)
                    MessageBox.Show("Carrying capacity can't be less than 0 and more than 30");
                }
                else
                {
                    if (EnginePowerTextBox.Text != String.Empty)
                    {
                        helicopter.CarryingCapacity = int.Parse(HeightTextBox.Text);
                    }
                }
            }

            if (int.Parse(EnginePowerTextBox.Text) < 0 && int.Parse(EnginePowerTextBox.Text) > 5000)
            {
                //if (EnginePowerTextBox.Text != String.Empty)
                MessageBox.Show("Engine power capacity can't be less than 0 and more than 5000");
            }
            else
            {
                if (EnginePowerTextBox.Text != String.Empty)
                {
                    helicopter.EnginePower = int.Parse(HeightTextBox.Text);
                }
            }

            Helicopters.Add(helicopter);
            //  }


            //if (EnginePowerTextBox.Text != String.Empty)
            //    helicopter.EnginePower = int.Parse(EnginePowerTextBox.Text);
        }
示例#6
0
        private void ButtonClickAdd(object sender, RoutedEventArgs e)
        {
            Helicopter helicopter = new Helicopter();

            if (helicopter != null)
            {
                if (string.IsNullOrEmpty(ModelTextBox.Text))
                {
                    MessageBox.Show("Model can't be empty");
                    return;
                }
                else
                {
                    helicopter.Model = ModelTextBox.Text;
                }

                if (string.IsNullOrEmpty(LengthTextBox.Text))
                {
                    MessageBox.Show("Length can't be empty");
                    return;
                }
                else if (Convert.ToInt32(LengthTextBox.Text) < 1 || Convert.ToInt32(LengthTextBox.Text) > 50)
                {
                    MessageBox.Show("Length can't be less than 0 and more than 50");
                    return;
                }
                else
                {
                    helicopter.Length = int.Parse(LengthTextBox.Text);
                }

                if (string.IsNullOrEmpty(HeightTextBox.Text))
                {
                    MessageBox.Show("Height can't be empty");
                    return;
                }
                else if (int.Parse(HeightTextBox.Text) < 1 || int.Parse(HeightTextBox.Text) > 20)
                {
                    MessageBox.Show("Height can't be less than 0 and more than 20");
                    return;
                }
                else
                {
                    helicopter.Height = int.Parse(HeightTextBox.Text);
                }

                if (string.IsNullOrEmpty(CarryingСapacityTextBox.Text))
                {
                    MessageBox.Show("Carrying capacity can't be empty");
                    return;
                }
                else if (int.Parse(CarryingСapacityTextBox.Text) < 1 || int.Parse(CarryingСapacityTextBox.Text) > 30)
                {
                    MessageBox.Show("Carrying capacity can't be less than 0 and more than 30");
                    return;
                }
                else
                {
                    helicopter.CarryingCapacity = int.Parse(CarryingСapacityTextBox.Text);
                }

                if (string.IsNullOrEmpty(EnginePowerTextBox.Text))
                {
                    MessageBox.Show("Engine power can't be empty");
                    return;
                }
                else if (int.Parse(EnginePowerTextBox.Text) < 1 || int.Parse(EnginePowerTextBox.Text) > 5000)
                {
                    MessageBox.Show("Engine power capacity can't be less than 0 and more than 10000");
                    return;
                }
                else
                {
                    helicopter.EnginePower = int.Parse(EnginePowerTextBox.Text);
                }

                Helicopters.Add(helicopter);
            }
        }