Ejemplo n.º 1
0
Archivo: Form1.cs Proyecto: hik023/unn3
        private void btnCopy_Click(object sender, EventArgs e)
        {
            autoTable.Rows.Clear();
            foreach (Car el in listOfCars)
            {
                if (el.number == index_to_copy + 1)
                {
                    if (el.type == "Легковая")
                    {
                        LightCar copied_car = new LightCar(el.model, el.age, el.price);
                        copied_car.number = number;
                        number           += 1;
                        listOfCars.Add(copied_car);
                    }
                    else
                    {
                        HugeCar copied_car = new HugeCar(el.model, el.age, el.price);
                        copied_car.number = number;
                        number           += 1;
                        listOfCars.Add(copied_car);
                    }

                    break;
                }
            }
            DrawTable();
        }
Ejemplo n.º 2
0
        public void Get_list(List <Car> list)
        {
            foreach (Car el in list)
            {
                switch (el.type)
                {
                case "Легковая":
                    Console.WriteLine(el.GetType());
                    LightCar item1 = el as LightCar;
                    DataRow  row1  = autoTable.NewRow();
                    row1[colNumber]          = item1.number;
                    row1[colCarType]         = item1.type;
                    row1[colCarModel]        = item1.model;
                    row1[colAge]             = item1.age;
                    row1[colPriceNew]        = item1.price;
                    row1[colPriceCalculated] = item1.price_calculation();

                    autoTable.Rows.Add(row1);
                    break;

                case "Грузовая":
                    HugeCar item2 = el as HugeCar;
                    DataRow row2  = autoTable.NewRow();
                    row2[colNumber]          = item2.number;
                    row2[colCarType]         = item2.type;
                    row2[colCarModel]        = item2.model;
                    row2[colAge]             = item2.age;
                    row2[colPriceNew]        = item2.price;
                    row2[colPriceCalculated] = item2.price_calculation();

                    autoTable.Rows.Add(row2);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
Archivo: Form1.cs Proyecto: hik023/unn3
        private void btnAdd_Click(object sender, EventArgs e)
        {
            autoTable.Rows.Clear();
            try
            {
                switch (cbType.Text)
                {
                case "Легковой":

                    LightCar item1 = new LightCar(
                        tbModel.Text, tbAge.Text, tbPrice.Text);
                    item1.number = number;
                    number      += 1;
                    listOfCars.Add(item1);

                    break;

                case "Грузовой":

                    HugeCar item2 = new HugeCar(
                        tbModel.Text, tbAge.Text, tbPrice.Text);
                    item2.number = number;
                    number      += 1;
                    listOfCars.Add(item2);

                    break;

                default:
                    MessageBox.Show("Выберите тип машины!");
                    break;
                }
            }
            catch
            {
                MessageBox.Show("Введены не корректные данные \nили не все поля заполнены!");
            }

            DrawTable();
        }