コード例 #1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            int carType = typeBox.SelectedIndex;

            switch (carType)
            {
            case 0:
            {
                int seats = 0;
                if (Int32.TryParse(additionalBox.Text, out seats))
                {
                    FamilyCar tmp = new FamilyCar(entries[indexEdited].id, brandBox.Text, modelBox.Text, yearBox.Text, seats);
                    entries[indexEdited] = tmp;
                    indexEdited          = -1;
                    editionInPlace(false, indexEdited);
                    break;
                }
                else
                {
                    MessageBox.Show("Invalid number of seats.", "Number of seats in vehicle.");
                }
                break;
            }

            case 1:
            {
                OffroadCar tmp = new OffroadCar(entries[indexEdited].id, brandBox.Text, modelBox.Text, yearBox.Text, additionalCheckbox.Checked);
                entries[indexEdited] = tmp;
                indexEdited          = -1;
                editionInPlace(false, indexEdited);
                break;
            }
            }
        }
コード例 #2
0
        private void editionInPlace(bool setEdition, int carType)
        {
            addEntry.Enabled     = !setEdition;
            typeBox.Enabled      = !setEdition;
            searchButton.Enabled = !setEdition;
            saveButton.Enabled   = setEdition;

            if (setEdition)
            {
                brandBox.Text = entries[indexEdited].brand;
                modelBox.Text = entries[indexEdited].model;
                yearBox.Text  = entries[indexEdited].year;

                switch (carType)
                {
                case 0:
                {
                    FamilyCar tmp = (FamilyCar)entries[indexEdited];
                    additionalBox.Text = tmp.seatsValue.ToString();
                    break;
                }

                case 1:
                {
                    OffroadCar tmp = (OffroadCar)entries[indexEdited];
                    additionalCheckbox.Checked = tmp.hasDifflock;
                    break;
                }
                }
            }
        }
コード例 #3
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            string search = searchBox.Text;
            bool   found;

            searchInPlace(true);

            foreach (Car entry in entries)
            {
                found = false;
                int carType = convertStringToType(entry.ToString());

                if (String.Equals(search, entry.id.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    found = true;
                }
                if (String.Equals(search, entry.brand.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    found = true;
                }
                if (String.Equals(search, entry.model.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    found = true;
                }
                if (String.Equals(search, entry.year.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    found = true;
                }

                switch (carType)
                {
                case 0:
                {
                    FamilyCar tmp = (FamilyCar)entry;
                    if (String.Equals(search, tmp.seatsValue.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        found = true;
                    }
                    break;
                }

                case 1:
                {
                    OffroadCar tmp = (OffroadCar)entry;
                    if (String.Equals(search, tmp.hasDifflock.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        found = true;
                    }
                    ;
                    break;
                }
                }
                if (found)
                {
                    searchList.Add(entry);
                }
            }
        }
コード例 #4
0
        private void displayProperties(int index, BindingList <Car> bindingList)
        {
            int    carTypeInt    = convertStringToType(bindingList[index].ToString());
            string carTypeString = convertIntToType(carTypeInt);
            String properties;

            switch (carTypeInt)
            {
            case 0:
            {
                FamilyCar tmp = (FamilyCar)bindingList[index];
                properties = "Type of vehicle: " + carTypeString
                             + "\nID: " + bindingList[index].id
                             + "\nBrand: " + bindingList[index].brand
                             + "\nModel: " + bindingList[index].model
                             + "\nYear: " + bindingList[index].year
                             + "\nSeats amount: " + tmp.seatsValue;


                MessageBox.Show(properties, "Properties of car.");
                break;
            }

            case 1:
            {
                OffroadCar tmp = (OffroadCar)bindingList[index];
                properties = "Type of vehicle: "
                             + carTypeString + "\nID: "
                             + bindingList[index].id + "\nBrand: "
                             + bindingList[index].brand + "\nModel: "
                             + bindingList[index].model + "\nYear: "
                             + bindingList[index].year + "\nHas differential lock: "
                             + tmp.hasDifflock;

                MessageBox.Show(properties, "Properties of car.");
                break;
            }
            }
        }
コード例 #5
0
        private void addEntry_Click(object sender, EventArgs e)
        {
            if (brandBox.Text != "" && modelBox.Text != "" && yearBox.Text != "")
            {
                switch (typeBox.SelectedIndex)
                {
                case -1:
                {
                    MessageBox.Show("Type not selected.");
                    break;
                }

                case 0:
                {
                    int seats = 0;
                    if (Int32.TryParse(additionalBox.Text, out seats))
                    {
                        FamilyCar tmp = new FamilyCar(index, brandBox.Text, modelBox.Text, yearBox.Text, seats);
                        entries.Add(tmp);
                        index++;
                    }
                    else
                    {
                        MessageBox.Show("Invalid number of seats.", "Number of seats in vehicle.");
                    }
                    break;
                }

                case 1:
                {
                    OffroadCar tmp = new OffroadCar(index, brandBox.Text, modelBox.Text, yearBox.Text, additionalCheckbox.Checked);
                    entries.Add(tmp);
                    index++;
                    break;
                }
                }
            }
        }