Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // ignore ssl not trusted certificate
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            var https_client = new hRef.CarListClient("https");

            https_client.Open();

            Car c;

            c = new PassengerCar();

            c.ՀՀ     = 5;
            c.Model  = "Model";
            c.Vendor = "Vendor";
            c.Year   = 2018;
            ((PassengerCar)c).Passengers = 25;

            https_client.SetCar(c);

            Console.WriteLine("Set");

            c = https_client.GetCar(5);

            Console.WriteLine("Get");

            Console.WriteLine(((PassengerCar)c).Passengers.ToString());

            https_client.Close();

            Console.ReadKey();
        }
Exemplo n.º 2
0
 private void ShowInfoBtn_Click(object sender, EventArgs e)
 {
     if (int.TryParse(NumberTxtBox.Text, out int needNum))
     {
         foreach (Car car in cars)
         {
             if (car.Number == needNum)
             {
                 if (car.Model == "Легковой")
                 {
                     PassengerCar PassCar = (PassengerCar)car;
                     richTextBox1.Text = $"Номер выбранного автомобиля: {PassCar.Number}\nЕго модель: {PassCar.Model}\nПробег: " +
                                         $"{PassCar.Mileage}\nВместительность бака:  {PassCar.FuelCapacity} Расход бензина: {PassCar.FuelСonsumption}\nВместительность: " +
                                         $"{PassCar.PassangerCapacity} пасажира\nТекущее кол-во пассажиров: {PassCar.CurrentPassenger}\n";
                 }
                 else if (car.Model == "Грузовой")
                 {
                     Truck truck = (Truck)car;
                     richTextBox1.Text = $"Номер выбранного автомобиля: {truck.Number}\nЕго модель: {truck.Model}\nПробег: " +
                                         $"{truck.Mileage}\nВместительность бака: {truck.FuelCapacity} Расход бензина: {truck.FuelСonsumption}\n Грузоподъёмность: " +
                                         $"{truck.CarryingCapacity}\n Текущий груз: {truck.CurrentGoodsWeight}\n";
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Student student = new Student();

            //student.Age = 18;
            student.Name = "Какой-то студент";
            Console.WriteLine(student.Name);

            //StudentWithGrant studentWithGrant = new StudentWithGrant();
            //studentWithGrant.Grant = 500;

            Person person = student;

            person.Name = "Какое-то имя";
            Console.WriteLine(person.Name);

            Student newStudent = (Student)person;

            Console.WriteLine(newStudent.Name);

            PassengerCar passengerCar = new PassengerCar();
            Vehicle      vehicle      = passengerCar;

            Console.ReadLine();
        }
Exemplo n.º 4
0
        public void TestAddCar()
        {
            int countAfterAdd = 1;

            service = new Service("Staff", "Client");
            Car car = new PassengerCar(CarsType.Sedan);

            service.AddCar(car);
            Assert.AreEqual(countAfterAdd, service.GetCarsCollection().Count);
        }
Exemplo n.º 5
0
        public void TestRemoveCarCorrect()
        {
            int elementId        = 0;
            int countAfterRemove = 0;

            service = new Service("Staff", "Client");
            Car car = new PassengerCar(CarsType.Sedan);

            service.AddCar(car);
            service.RemoveCar(elementId);
            Assert.AreEqual(countAfterRemove, service.GetCarsCollection().Count);
        }
Exemplo n.º 6
0
        public void TestRemoveCarInCorrect()
        {
            int elementId = 1;

            service = new Service("Staff", "Client");
            Car car = new PassengerCar(CarsType.Sedan);

            service.AddCar(car);
            try
            {
                service.RemoveCar(elementId);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }
        }
Exemplo n.º 7
0
        public void TestSerializeServiceTree()
        {
            PassengerCar car     = new PassengerCar(CarsType.Coupe);
            Service      service = new Service("Staff", "Client");
            Country      country = new Country("RU", "Russia");

            car.Country = country;
            service.AddCar(car);

            XmlSerializer formatter = new XmlSerializer(
                typeof(Service),
                new Type[] { typeof(PassengerCar), typeof(Country) }
                );

            using (FileStream fs = new FileStream("tree.xml", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, service);
            }
        }
Exemplo n.º 8
0
 private void AddCarsBtn_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < dataGridViewCars.RowCount - 1; i++)
     {
         if (dataGridViewCars[0, i].Value.ToString() == "Легковой")
         {
             if (int.TryParse(dataGridViewCars[1, i].Value.ToString(), out int Number) &&
                 double.TryParse(dataGridViewCars[2, i].Value.ToString(), out double FuelCapacity) &&
                 double.TryParse(dataGridViewCars[3, i].Value.ToString(), out double FuelConsumption) &&
                 double.TryParse(dataGridViewCars[4, i].Value.ToString(), out double Miliage) &&
                 int.TryParse(dataGridViewCars[5, i].Value.ToString(), out int PassangerCappacity))
             {
                 var car = new PassengerCar(Number, FuelCapacity, FuelConsumption, Miliage, PassangerCappacity);
                 cars.Add(car);
             }
             else
             {
                 MessageBox.Show("Некорректные данные в строке " + dataGridViewCars[i, i].RowIndex.ToString());
             }
         }
         else if (dataGridViewCars[0, i].Value.ToString() == "Грузовой")
         {
             if (int.TryParse(dataGridViewCars[1, i].Value.ToString(), out int Number) &&
                 double.TryParse(dataGridViewCars[2, i].Value.ToString(), out double FuelCapacity) &&
                 double.TryParse(dataGridViewCars[3, i].Value.ToString(), out double FuelConsumption) &&
                 double.TryParse(dataGridViewCars[4, i].Value.ToString(), out double Miliage) &&
                 int.TryParse(dataGridViewCars[1, i].Value.ToString(), out int CarryingCapacity))
             {
                 var car = new Truck(Number, FuelCapacity, FuelConsumption, Miliage, CarryingCapacity);
                 cars.Add(car);
             }
             else
             {
                 MessageBox.Show("Некорректные данные в строке " + dataGridViewCars[i, i].OwningRow);
             }
         }
         else
         {
             MessageBox.Show("Модель не опознана в строке " + dataGridViewCars[0, i].RowIndex.ToString());
         }
     }
 }
Exemplo n.º 9
0
        private void Button_AddCar_Click(object sender, EventArgs e)
        {
            int currentIndex = listBox_CarsCountry.SelectedIndex;

            try
            {
                int      carYear   = int.Parse(textBox_CarYear.Text);
                float    carWeight = float.Parse(textBox_CarWeight.Text);
                CarsType carsType  = (CarsType)listBox_CarsType.SelectedItem;
                Car      car       = new PassengerCar(carsType);
                car.Weight  = carWeight;
                car.Year    = carYear;
                car.Country = countryCollection.GetCollection()[currentIndex];
                carsCollection.Add(car);
                RefreshListCars();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 10
0
        private void btnSetCar_Click(object sender, EventArgs e)
        {
            int    id     = int.Parse(tbxId.Text);
            string vendor = tbxVendor.Text;
            string model  = tbxModel.Text;
            int    year   = int.Parse(tbxYear.Text);
            Car    car;

            switch (cbxType.SelectedIndex)
            {
            case 0:
                car = new Car();
                break;

            case 1:
                car = new TruckCar {
                    Capacity = double.Parse(tbxType.Text, CultureInfo.GetCultureInfo("en-US"))
                };
                break;

            case 2:
                car = new PassengerCar {
                    Passengers = int.Parse(tbxType.Text, CultureInfo.GetCultureInfo("en-US"))
                };
                break;

            default:
                car = new Car();
                break;
            }

            car.Id     = id;
            car.Vendor = vendor;
            car.Model  = model;
            car.Year   = year;

            _client.SetCar(car);
        }
Exemplo n.º 11
0
 public Client(CarFactory factory)
 {
     _passengerCar = factory.CreatePassengerCar();
     _truck        = factory.CreateTruck();
     _bus          = factory.CreateBus();
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            var  cars = new List <Car>();
            int  iter;
            bool numberCheck = true;

            do
            {
                Console.WriteLine("Выберите:\n1 - добавить легковой автомобиль\n2 - добавить грузовой автомобиль\n3 - выбрать автомобиль из списка автомобилей\n4 - выйти");
                bool iterSuccess = int.TryParse(Console.ReadLine(), out iter);
                switch (iter)
                {
                case 1:
                    Console.WriteLine("Введите номер: ");
                    numberCheck = true;
                    bool numberSuccess = int.TryParse(Console.ReadLine(), out int number);
                    for (int i = 0; i < cars.Count; i++)
                    {
                        if (cars[i].Number == number)
                        {
                            numberCheck = false;
                            Console.WriteLine("Автомобиль с таким номером существует, попробуйте снова ");
                            break;
                        }
                    }
                    if (!numberCheck)
                    {
                        break;
                    }
                    Console.WriteLine("Введите ёмкость бензобака: ");
                    bool fuelCapacitySuccess = double.TryParse(Console.ReadLine(), out double fuelCappacity);
                    Console.WriteLine("Введите расход бензина: ");
                    bool fuelСonsumptionSuccess = double.TryParse(Console.ReadLine(), out double fuelCunsumption);
                    Console.WriteLine("Введите пробег: ");
                    bool mileageSuccess = double.TryParse(Console.ReadLine(), out double Mileage);
                    Console.WriteLine("Введите колличество мест: ");
                    bool passangerCapacitySuccess = int.TryParse(Console.ReadLine(), out int passangerCapacity);
                    if (numberSuccess && fuelCapacitySuccess && fuelСonsumptionSuccess &&
                        mileageSuccess && passangerCapacitySuccess)
                    {
                        var passCar = new PassengerCar(number, fuelCappacity,
                                                       fuelCunsumption, Mileage, passangerCapacity);
                        cars.Add(passCar);
                        break;
                    }
                    else
                    {
                        break;
                    }


                case 2:
                    numberCheck = true;
                    Console.WriteLine("Введите номер: ");
                    bool truckNumSuccess = int.TryParse(Console.ReadLine(), out int truckNum);
                    for (int i = 0; i < cars.Count; i++)
                    {
                        if (cars[i].Number == truckNum)
                        {
                            numberCheck = false;
                            Console.WriteLine("Автомобиль с таким номером существует, попробуйте снова ");
                        }
                    }
                    if (!numberCheck)
                    {
                        break;
                    }
                    Console.WriteLine("Введите ёмкость бензобака: ");
                    bool truckFuelCapacitySuccess = double.TryParse(Console.ReadLine(), out double truckFuelCapacity);
                    Console.WriteLine("Введите расход бензина: ");
                    bool truckFuelСonsumptionSuccess = double.TryParse(Console.ReadLine(), out double truckFuelСonsumption);
                    Console.WriteLine("Введите пробег: ");
                    bool truckMileageSuccess = double.TryParse(Console.ReadLine(), out double truckMileage);
                    Console.WriteLine("Введите грузоподъёмность: ");
                    bool carryingCapacitySuccess = int.TryParse(Console.ReadLine(), out int carryingCapacity);
                    if (truckNumSuccess && truckFuelCapacitySuccess && truckFuelСonsumptionSuccess &&
                        truckMileageSuccess && carryingCapacitySuccess)
                    {
                        var truckCar = new Truck(truckNum, truckFuelCapacity,
                                                 truckFuelСonsumption, truckMileage, carryingCapacity);
                        cars.Add(truckCar);
                        break;
                    }
                    else
                    {
                        break;
                    }

                case 3:
                    Console.WriteLine("Введите номер нужного автомобиля: ");
                    bool numSuccess = int.TryParse(Console.ReadLine(), out int needNum);
                    if (numSuccess)
                    {
                        for (int i = 0; i < cars.Count; i++)
                        {
                            if (cars[i].Number == needNum)
                            {
                                if (cars[i].Model == "Легковой")
                                {
                                    PassengerCar car = (PassengerCar)cars[i];
                                    Console.WriteLine($"Номер выбранного автомобиля: {car.Number}\nЕго модель: {car.Model}\nПробег: " +
                                                      $"{car.Mileage}\nВместительность бака:  {car.FuelCapacity} Расход бензина: {car.FuelСonsumption}\nВместительность: " +
                                                      $"{car.PassangerCapacity} пасажира\nТекущее кол-во пассажиров: {car.CurrentPassenger}\n");
                                    break;
                                }
                                else if (cars[i].Model == "Грузовой")
                                {
                                    Truck car = (Truck)cars[i];
                                    Console.WriteLine($"Номер выбранного автомобиля: {car.Number}\nЕго модель: {car.Model}\nПробег: " +
                                                      $"{car.Mileage}\nВместительность бака: {car.FuelCapacity} Расход бензина: {car.FuelСonsumption}\n Грузоподъёмность: " +
                                                      $"{car.CarryingCapacity}\n Текущий груз: {car.CurrentGoodsWeight}\n");
                                    break;
                                }
                            }
                        }
                    }

                    break;
                }
            } while (iter != 4);
        }
Exemplo n.º 13
0
 public void TestInitialize()
 {
     car = new PassengerCar(CarsType.Sedan);
 }