Пример #1
0
        public void ProductDelete(int current)
        {
            int new_size = size - 1;

            CarShop[] temp_array = new CarShop[new_size];
            Array.Copy(car, 0, temp_array, 0, current);
            Array.Copy(car, current + 1, temp_array, current, size - current - 1);
            ClearAll();
            size  = new_size;
            index = size;
            ArrayResize();
            Array.Copy(temp_array, 0, car, 0, size);
            Array.Clear(temp_array, 0, size);
        }
Пример #2
0
        private void sortSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            CarShop[] sort       = new CarShop[1];
            CarShop[] temp_array = new CarShop[Storage.size];
            for (int i = 0; i < Storage.size; i++)
            {
                temp_array[i] = Storage.car[i];
            }
            switch (sortSelection.Text)
            {
            case "Alphabetically":
                for (int i = 0; i < Storage.car.Length - 1; i++)
                {
                    for (int j = i + 1; j < Storage.car.Length; j++)
                    {
                        if (string.Compare(Storage.car[i].product_name, Storage.car[j].product_name) > 0)
                        {
                            sort[0]        = Storage.car[i];
                            Storage.car[i] = Storage.car[j];
                            Storage.car[j] = sort[0];
                        }
                    }
                }
                break;

            case "By price (from cheap to exp.)":
                for (int i = 0; i < Storage.car.Length - 1; i++)
                {
                    for (int j = i + 1; j < Storage.car.Length; j++)
                    {
                        if (Storage.car[i].price > Storage.car[j].price)
                        {
                            sort[0]        = Storage.car[i];
                            Storage.car[i] = Storage.car[j];
                            Storage.car[j] = sort[0];
                        }
                    }
                }
                break;

            case "By price (from exp. to cheap)":
                for (int i = 0; i < Storage.car.Length - 1; i++)
                {
                    for (int j = i + 1; j < Storage.car.Length; j++)
                    {
                        if (Storage.car[i].price < Storage.car[j].price)
                        {
                            sort[0]        = Storage.car[i];
                            Storage.car[i] = Storage.car[j];
                            Storage.car[j] = sort[0];
                        }
                    }
                }
                break;

            case "By store number":
                for (int i = 0; i < Storage.car.Length - 1; i++)
                {
                    for (int j = i + 1; j < Storage.car.Length; j++)
                    {
                        if (Storage.car[i].store_number > Storage.car[j].store_number)
                        {
                            sort[0]        = Storage.car[i];
                            Storage.car[i] = Storage.car[j];
                            Storage.car[j] = sort[0];
                        }
                    }
                }
                break;
            }
            SwapBack(temp_array);
        }