Пример #1
0
        protected void GetCarBtn_Click(object sender, EventArgs e)
        {
            using (var client = new CarServiceReference.CarServiceClient())
            {
                int carId = int.Parse(IdTxtBx.Text);
                var car   = client.GetCar(carId);

                if (car != null)
                {
                    MarkTxtBx.Text  = car.Mark;
                    ModelTxtBx.Text = car.Model;
                    YearTxtBx.Text  = car.YearOfProduction.Year.ToString();
                    EngineTypeDropDownList.SelectedIndex = (int)car.EngineType;

                    if (car.EngineType == CarServiceReference.EngineType.Electric)
                    {
                        var electricCar = (CarServiceReference.ElectricCar)car;
                        RangeTxtBx.Text = electricCar.RangeInKilometers.ToString();
                    }
                    else
                    {
                        var oilFuelCar = (CarServiceReference.OilFuelCar)car;
                        EngineCCTxtBx.Text    = oilFuelCar.EngineСС.ToString();
                        EnginePowerTxtBx.Text = oilFuelCar.EnginePower.ToString();
                    }

                    ResultLabel.Text = "Sucessfull get car";
                }
                else
                {
                    ResultLabel.Text = "Err get car";
                }
            }
        }
Пример #2
0
        protected void SaveCarBtn_Click(object sender, EventArgs e)
        {
            using (var client = new CarServiceReference.CarServiceClient())
            {
                int carId = int.Parse(IdTxtBx.Text);

                CarServiceReference.Car car = null;
                if (EngineTypeDropDownList.SelectedIndex == 1)
                {
                    car = new CarServiceReference.ElectricCar()
                    {
                        Id                = carId,
                        Mark              = MarkTxtBx.Text,
                        Model             = ModelTxtBx.Text,
                        YearOfProduction  = Convert.ToDateTime(YearTxtBx.Text),
                        EngineType        = (CarServiceReference.EngineType)EngineTypeDropDownList.SelectedIndex,
                        RangeInKilometers = int.Parse(RangeTxtBx.Text)
                    };

                    SaveCar(car);
                }
                else if (EngineTypeDropDownList.SelectedIndex == 2)
                {
                    car = new CarServiceReference.OilFuelCar()
                    {
                        Id               = carId,
                        Mark             = MarkTxtBx.Text,
                        Model            = ModelTxtBx.Text,
                        YearOfProduction = Convert.ToDateTime(YearTxtBx.Text),
                        EngineType       = (CarServiceReference.EngineType)EngineTypeDropDownList.SelectedIndex,
                        EnginePower      = int.Parse(EnginePowerTxtBx.Text),
                        EngineСС         = int.Parse(EngineCCTxtBx.Text)
                    };

                    SaveCar(car);
                }
                else
                {
                    ResultLabel.Text = "Choose engine type";
                }

                void SaveCar(CarServiceReference.Car carForSave)
                {
                    client.SaveCar(carForSave);
                    ResultLabel.Text = "Car saved";
                }
            }
        }