Программирование в среде VisualFoxPro. Создание базы данных «Зоопарк», страница 4

   ON  Deliveries.product_id = Products.id ;

   INTO ARRAY delivs

thisform.list.refresh

Добавлениепитания:

Рис. 20. Форма добавление питания.

Код метода Click кнопки «Добавить»:

public tmp(2)

if reccount("eat") > 0

            SELECT MAX(id) FROM eat INTO ARRAY tmp

else

            tmp[1] = -1

endif

INSERT INTO eat (id, amount, animal_id, deliver_id) VALUES (tmp[1]+1, thisform.amount.value, val(thisform.animal.value), val(thisform.deliver.value))

messagebox("Питание добавлено!")

Код метода Click кнопки «Очистить»:

thisform.amount.value=0

Добавлениеживотного:

Рис. 21. Форма добавление животного.

Код метода Click кнопки «Добавить»:

public tmp(2)

if reccount("animals") > 0

            SELECT MAX(id) FROM animals INTO ARRAY tmp

else

            tmp[1] = -1

endif

INSERT INTO animals (id, name, gender, year, date, cost, country_id, detachment_id, kind_id, ill, pregnat, sp_name, sp_money_min, sp_money_max);

            VALUES (tmp[1]+1, thisform.animal.value, thisform.gender.value, thisform.year.value, thisform.date.value, thisform.cost.value, val(thisform.country.value), val(thisform.detachment.value), val(thisform.kind.value), thisform.ill.value, thisform.pregnat.value, thisform.sp_name.value, thisform.sp_money_min.value, thisform.sp_money_max.value)

messagebox("Животное добавлено!")

Код метода Click кнопки «Очистить»:

thisform.animal.value=""

thisform.cost.value=0

thisform.sp_name.value=""

thisform.sp_money_min.value=0

thisform.sp_money_max.value=0

3.4. Запросы к базе данных для просмотра информации.

Вывод животных без сортировки:

SELECT Animals.id, Animals.name as "Имя",;

  Detachment.name as "Отряд", Kind.name as "Вид", Kind.location as "Место_обитания", Kind.unique as "Редкость",;

  Animals.gender as "Пол", Animals.year as "Год_рождения",;

  Animals.cost as "Стоимость", Animals.date as "Дата_приобретения", Animals.ill as "Больное", Animals.pregnat as "Беременное", Animals.sp_name as "Спонсор",;

  Animals.sp_money_min as "Вклад_cпонсора_от", Animals.sp_money_max as "Вклад_спонсора_до", Country.name as "Страна";

 FROM  data1!animals LEFT OUTER JOIN data1!country ON Animals.country_id = Country.id;

    LEFT OUTER JOIN data1!detachment ON Animals.detachment_id = Detachment.id ;

    LEFT OUTER JOIN data1!kind ON Animals.kind_id = Kind.id ;

 ORDER BY Animals.id

Вывод животных с сортировкой по году рождения:

SELECT Animals.id, Animals.name as "Имя",;

  Detachment.name as "Отряд", Kind.name as "Вид", Kind.location as "Место_обитания", Kind.unique as "Редкость",;

  Animals.gender as "Пол", Animals.year as "Год_рождения",;

  Animals.cost as "Стоимость", Animals.date as "Дата_приобретения", Animals.ill as "Больное", Animals.pregnat as "Беременное", Animals.sp_name as "Спонсор",;

  Animals.sp_money_min as "Вклад_cпонсора_от", Animals.sp_money_max as "Вклад_спонсора_до", Country.name as "Страна";

 FROM  data1!animals LEFT OUTER JOIN data1!country ON Animals.country_id = Country.id;

    LEFT OUTER JOIN data1!detachment ON Animals.detachment_id = Detachment.id ;

    LEFT OUTER JOIN data1!kind ON Animals.kind_id = Kind.id ;

 ORDER BY Animals.year

Вывод животных с сортировкой по алфавиту:

SELECT Animals.id, Animals.name as "Имя",;

  Detachment.name as "Отряд", Kind.name as "Вид", Kind.location as "Место_обитания", Kind.unique as "Редкость",;

  Animals.gender as "Пол", Animals.year as "Год_рождения",;

  Animals.cost as "Стоимость", Animals.date as "Дата_приобретения", Animals.ill as "Больное", Animals.pregnat as "Беременное", Animals.sp_name as "Спонсор",;