Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Отчёт по БД / курсовик.doc
Скачиваний:
31
Добавлен:
15.06.2014
Размер:
99.33 Кб
Скачать

Процедура контроля ссылочной целостности при изменении данных

procedure TForm1.Button6Click(Sender: TObject);

var

j:integer; //переменная для хранения измененного номера, неизмененный номер хранится в глобальной //переменной i

begin

// Если dbgrid в фокусе, то сохраняем изменения в соотв. таблицы, обновляем таблицу.

if dbgrid1.DataSource=dataSource1 then

begin

Table1.post;

mainform.Table1.Refresh;

end;

//Если изменили № товара в таблице “Заказ товаропроизвод-лю”, то устанавливаем связь

if dbgrid1.DataSource=dataSource2 then

begin

table6.MasterSource:=dataSource2;

table6.MasterFields:='N_t';

//если в таблице “Товар” нет данного “Товара”, предупреждаем, и предпренимаем соответс-ие действия.

if table6['N_t']<1 then begin form15.show; form1.Enabled:=false; end;

//Отключаем связь

table6.MasterFields:='';

table6.MasterSource:=nil;

end;

if dbgrid1.DataSource=dataSource3 then

begin

Table3.post;

mainform.Table3.Refresh;

end;

if dbgrid1.DataSource=dataSource4 then

begin

Table4.post;

mainform.Table4.Refresh;

end;

if dbgrid1.DataSource=dataSource5 then

begin

Table5.post;

mainform.Table5.Refresh;

end;

//Редактирование в 6–ой таблице

if dbgrid1.DataSource=dataSource6 then

begin

Table6.post;

j:=table6['N_t']; //сохранение изменения

table1.Filter:='N_t='+inttostr(i);//включения фильтра

table1.Filtered:=true;

//Изменения записи в 1-ой таблице

while not table1.Eof do begin

table1.edit;// Открытие для редактирования

table1['N_t']:=j; //редактирование

table1.Post; //Сохранение изменения

end;

table2.Filter:='N_t='+inttostr(i); );//включения фильтра

table2.Filtered:=true;

//Изменения записи в 2-ой таблице

while not table2.Eof do begin

table2.edit; // Открытие для редактирования

table2['N_t']:=j; //редактирование

table2.Post; //Сохранение изменения

end;

//Обновления изменений

mainform.Table6.Refresh;

mainform.Table1.Refresh;

mainform.Table2.Refresh;

// Отключение фильтра

table1.Filtered:=false;

table2.Filtered:=false;

end;

Процедура поиска по 1-ой таблице

procedure TForm2.Button1Click(Sender: TObject);

var

s:string;

begin

//Поиск по 1-ой таблице

if combobox1.ItemIndex=0 then //Если выбрана 1-ая таблица

begin

// выбираем поле в таблице

if combobox2.ItemIndex=0 then s:='N_z';

if combobox2.ItemIndex=1 then s:='Date_z';

if combobox2.ItemIndex=2 then s:='N_pred';

if combobox2.ItemIndex=3 then s:='N_t';

if combobox2.ItemIndex=4 then s:='Kol';

if combobox2.ItemIndex=5 then s:='N_s';

with Table1 do

begin

Filter:=s+'='''+Edit1.Text+''''; //Включаем фильтр

Filtered:=True;

end;

dbgrid1.DataSource:=datasource1;

with mainform.Table1 do

begin

Filter:=s+'='''+Edit1.Text+''''; //Включаем фильтр

Filtered:=True;

end;

//Разрыв связей

mainform.table1.MasterFields:='';

mainform.table1.MasterSource:=nil;

mainform.table2.MasterFields:='';

mainform.table2.MasterSource:=nil;

mainform.table3.MasterFields:='';

mainform.table3.MasterSource:=nil;

mainform.table4.MasterFields:='';

mainform.table4.MasterSource:=nil;

mainform.table5.MasterFields:='';

mainform.table5.MasterSource:=nil;

mainform.table6.MasterFields:='';

mainform.table6.MasterSource:=nil;

//Установка связи по 1-ой Т

mainform.table3.MasterSource:=dataSource1;

mainform.table3.MasterFields:='N_pred';

mainform.table5.MasterSource:=dataSource1;

mainform.table5.MasterFields:='N_s';

mainform.table6.MasterSource:=dataSource1;

mainform.table6.MasterFields:='N_t';

mainform.table2.MasterSource:=dataSource6;

mainform.table2.MasterFields:='N_t';

mainform.table4.MasterSource:=dataSource2;

mainform.table4.MasterFields:='Pr';

…….……………………….

end;

procedure TMainForm.Edit1Change(Sender: TObject);

begin

//Поиск по 1-ой таблице

if t1=true then

begin

// установка поля в табл ице в зависимости от выбранного поля

if combobox1.ItemIndex=0 then table1.IndexFieldNames:='N_z';

if combobox1.ItemIndex=1 then table1.IndexFieldNames:='Date_z';

if combobox1.ItemIndex=2 then table1.IndexFieldNames:='N_pred';

if combobox1.ItemIndex=3 then table1.IndexFieldNames:='N_t';

if combobox1.ItemIndex=4 then table1.IndexFieldNames:='Kol';

if combobox1.ItemIndex=5 then table1.IndexFieldNames:='N_s';

with dbgrid1.DataSource.DataSet as TTable do //переход к соответствующей записи

FindNearest([TEdit(Sender).Text]);

end;

……………

End;

Соседние файлы в папке Отчёт по БД