procedure TForm3.DBGrid1DblClick(Sender: TObject);
begin
SelTab();
Form3.Close;
end;
procedure TForm3.FormShow(Sender: TObject);
begin
Edit1.SetFocus;
Edit1.Clear;
Edit2.Clear;
If (tbl='Ceha') then
begin
Edit2.Visible := True;
Edit1.Width := 161;
Label2.Visible := True;
end
else
begin
Edit1.Width := 225;
Edit2.Visible := False;
Label2.Visible := False;
end;
end;
procedure TForm3.delExecute(Sender: TObject);
begin
ForDel := DataModule2.Query1['id'];
DelZapros;
ShowZapros();
Edit1.Clear;
Edit2.Clear;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
InsEdit:=false;
ForEdit:='-1';
end;
procedure TForm3.DBGrid1CellClick(Column: TColumn);
begin
If (Tbl='Ceha') then
begin
Edit2.Text := SelectQ[pole3];
end;
Edit1.Text := SelectQ[pole2];
ForEdit:= SelectQ[pole1];
InsEdit := True;
end;
end.
unit Unit4;
interface
Uses ADODB;
var QueryString, TBL, pole1, pole2, Pole3, pole4, Pole5, pole6 : string;
pole7, pole8, pole9, pole10, pole11, pole12, pole13 : string;
ToIns, ToIns2, ToIns3, ToIns4, ToIns5, ToIns6, ToIns7, ToIns8 : string;
ToIns9, ToIns10, ToIns11, ToIns12, ToIns13, ForDel, ForEdit, ForOrder, Diap, TmpFiltr : string;
InsEdit,InsEdit2,InsEdit3,InsEdit4,InsEdit5 : boolean;
SelectQ : TADOQuery;
EditMode, ForSort, ForFiltr, EditMode2, EditMode3, EditMode4, EditIns, EditIns2 : boolean;
Procedure ShowZapros();
Procedure InsertZapros();
Procedure DelZapros();
Procedure SelTab();
Procedure ForReport();
implementation
Uses Dialogs, Unit2, Unit5, Unit6, Unit3, Unit7, Unit8, Unit1, Unit9, Unit10, DB;
Procedure ShowZapros();
var Polya, Tabli, Svyaz, MyKey : String;
begin
if ((Tbl='Operation')or(Tbl='Station')or(Tbl='Ceha')or
(Tbl='Front')or(Tbl='Gruz')or(Tbl='Rod_vagona')or
(Tbl='Raion_dvizheniya')or(Tbl='Ves')or(Tbl='Vid_uslug')) then
begin
QueryString := 'select * from ' + TBL + ' order by ' + pole2;
SelectQ := DataModule2.Query1;
end;
if (Tbl='Vagon') then
begin
QueryString := 'select * from Vagon V, Rod_vagona RV, Raion_dvizheniya RD where V.key_rod_vagona=RV.id and V.key_raion_dvizh=RD.id order by invent_nomer desc';
SelectQ := DataModule2.QShow;
end;
if (Tbl='Operations_s_vagonom') then
begin
MyKey := DataModule2.Qshow['v.id'];
SelectQ := DataModule2.QOSV;
Polya := 'OSV.*, SNACH.*, SKON.*, FNACH.*, FKON.*, O.*, G.*';
Tabli := 'vagon V, station SNACH, station SKON, front FNACH, front FKON, operation O, gruz G, Operations_s_vagonom OSV';
Svyaz:= 'OSV.key_station_otpr=SNACH.id and OSV.key_front_otpr=FNACH.id and OSV.key_station_naznach=SKON.id and OSV.key_front_naznach=FKON.id and OSV.key_operation=O.id and OSV.key_gruz=G.id and OSV.key_vagon=V.id and OSV.key_vagon=' + MyKey;
QueryString := 'select '+Polya+' from '+Tabli+' where '+Svyaz;
end;
if (Tbl='Uslugi_sv') then
begin
MyKey := DataModule2.QOSV['OSV.id'];
SelectQ := DataModule2.Quslugi;
Polya := 'USV.*, CNA.*, CS.*, ST.*, VU.*, V.*';
Tabli := 'Ceha CNA, Ceha CS, Uslugi_sv USV, Operations_s_vagonom OSV, Stoimost ST, Vid_uslug VU, Ves V';
Svyaz:= 'USV.key_uslugi=ST.id and USV.key_na=CNA.id and USV.key_s=CS.id and USV.key_vagon=OSV.id and ST.key_vid_uslug=VU.id and ST.key_ves=V.id and USV.key_vagon=' + MyKey;
QueryString := 'select '+Polya+' from '+Tabli+' where '+Svyaz;
end;
if (Tbl='Stoimost') then
begin
SelectQ := DataModule2.QSelUs;
Polya := ' VU.*, V.*, ST.*';
Tabli := 'Vid_uslug VU, Ves V, Stoimost ST';
Svyaz:= 'ST.key_vid_uslug=VU.id and ST.key_ves=V.id';
QueryString := 'select '+Polya+' from '+Tabli+' where '+Svyaz;
end;
with SelectQ do
begin
Close;
SQL.Clear;
SQL.Add(QueryString);
Open;
end;
if (Tbl='Vagon') then
begin
SelectQ.Fields[0].Visible := false;
SelectQ.Fields[7].Visible := false;
SelectQ.Fields[9].Visible := false;
SelectQ.Fields[10].Visible := false;
SelectQ.Fields[12].Visible := false;
Form1.DBGrid1.Columns[0].Title.Caption :='Месяц';
Form1.DBGrid1.Columns[1].Title.Caption :='Год';
Form1.DBGrid1.Columns[2].Title.Caption :='№ вагона';
Form1.DBGrid1.Columns[3].Title.Caption :='Инв. №';
Form1.DBGrid1.Columns[4].Title.Caption :='Изгот.';
Form1.DBGrid1.Columns[5].Title.Caption :='Грузопод. т.';
Form1.DBGrid1.Columns[6].Title.Caption :='Износ %';
Form1.DBGrid1.Columns[7].Title.Caption :='Род вагона';
Form1.DBGrid1.Columns[8].Title.Caption :='Район движения';
end;
if (Tbl='Operations_s_vagonom') then
begin
SelectQ.Fields[0].Visible := false;
SelectQ.Fields[1].Visible := false;
SelectQ.Fields[2].Visible := false;
SelectQ.Fields[3].Visible := false;
SelectQ.Fields[4].Visible := false;
SelectQ.Fields[7].Visible := false;
SelectQ.Fields[8].Visible := false;
SelectQ.Fields[12].Visible := false;
SelectQ.Fields[13].Visible := false;
SelectQ.Fields[15].Visible := false;
SelectQ.Fields[17].Visible := false;
SelectQ.Fields[19].Visible := false;
SelectQ.Fields[21].Visible := false;
SelectQ.Fields[23].Visible := false;
Form6.DBGrid1.Columns[0].Title.Caption :='Дата';
Form6.DBGrid1.Columns[1].Title.Caption :='Время';
Form6.DBGrid1.Columns[2].Title.Caption :='Вес';
Form6.DBGrid1.Columns[3].Title.Caption :='№ дор. вед.';
Form6.DBGrid1.Columns[4].Title.Caption :='№ вед.';
Form6.DBGrid1.Columns[5].Title.Caption :='Станция отпр.';
Form6.DBGrid1.Columns[6].Title.Caption :='Станция пол.';
Form6.DBGrid1.Columns[7].Title.Caption :='Фронт отпр.';
Form6.DBGrid1.Columns[8].Title.Caption :='Фронт пол.';
Form6.DBGrid1.Columns[9].Title.Caption :='Операция';
Form6.DBGrid1.Columns[10].Title.Caption :='Груз';
end;
if (Tbl='Uslugi_sv') then
begin
SelectQ.Fields[0].Visible := false;
SelectQ.Fields[2].Visible := false;
SelectQ.Fields[3].Visible := false;
SelectQ.Fields[4].Visible := false;
SelectQ.Fields[5].Visible := false;
SelectQ.Fields[7].Visible := false;
SelectQ.Fields[10].Visible := false;
SelectQ.Fields[13].Visible := false;
SelectQ.Fields[14].Visible := false;
SelectQ.Fields[15].Visible := false;
SelectQ.Fields[17].Visible := false;
SelectQ.Fields[19].Visible := false;
Form7.DBGrid1.Columns[0].Title.Caption :='Заказ';
Form7.DBGrid1.Columns[1].Title.Caption :='Стоимость заказа';
Form7.DBGrid1.Columns[2].Title.Caption :='№ цеха исп.';
Form7.DBGrid1.Columns[3].Title.Caption :='БС ц.и.';
Form7.DBGrid1.Columns[4].Title.Caption :='№ цеха заказ.';
Form7.DBGrid1.Columns[5].Title.Caption :='БС ц.з.';
Form7.DBGrid1.Columns[6].Title.Caption :='Стоим. усл.';
Form7.DBGrid1.Columns[7].Title.Caption :='Вид услуги';
Form7.DBGrid1.Columns[8].Title.Caption :='Единица измерения';
end;
if (Tbl='Stoimost') then
begin
SelectQ.Fields[0].Visible := false;
SelectQ.Fields[2].Visible := false;
SelectQ.Fields[4].Visible := false;
SelectQ.Fields[5].Visible := false;
SelectQ.Fields[6].Visible := false;
Form8.DBGrid1.Columns[0].Title.Caption :='Вид услуги';
Form8.DBGrid1.Columns[1].Title.Caption :='Единица измерения';
Form8.DBGrid1.Columns[2].Title.Caption :='Стоимость';
end;
if ((Tbl='Operation')or(Tbl='Station')or(Tbl='Ceha')or
(Tbl='Front')or(Tbl='Gruz')or(Tbl='Rod_vagona')or
(Tbl='Raion_dvizheniya')or(Tbl='Ves')or(Tbl='Vid_uslug')) then
begin
SelectQ.Fields[0].Visible := false;
Form3.DBGrid1.Columns[0].Title.Caption := Form3.Label1.Caption;
If (tbl='Ceha') then
begin
Form3.DBGrid1.Columns[1].Title.Caption := Form3.Label2.Caption;
end;
end;
end;
Procedure InsertZapros();
var
QueryString, Polya: string;
YN : Boolean;
begin
YN := false;
if ((Tbl='Operation')or(Tbl='Station')or(Tbl='Ceha')or
(Tbl='Front')or(Tbl='Gruz')or(Tbl='Rod_vagona')or
(Tbl='Raion_dvizheniya')or(Tbl='Ves')or(Tbl='Vid_uslug')) then
begin
SelectQ := DataModule2.Query1;
with DataModule2.Query1 do
begin
First;
while (not Eof) do
begin
if (ForEdit <> SelectQ['id']) then
begin
if DataModule2.Query1[pole2] = ToIns then
begin
YN:=true;
Break;
end;
end;
Next;
end;
end;
if InsEdit then
begin
If (tbl='Ceha') then
begin
QueryString := 'UPDATE '+TBL+' SET '+pole2+'='+#39+ToIns+#39+','+pole3+'='+#39+ToIns2+#39+ ' where '+pole1+'='+ForEdit;
end
else
begin
QueryString := 'UPDATE '+TBL+' SET '+pole2+'='+#39+ToIns+#39+' where '+pole1+'='+ForEdit;
end;
InsEdit := false;
end
else
begin
If (tbl='Ceha') then
begin
QueryString := 'insert into '+ TBL +' ('+pole2+','+pole3+') values ('+#39+ToIns+#39+','+#39+ToIns2+#39+')';
end
else
begin
QueryString := 'insert into '+ TBL +' ('+pole2+') values ('+#39+ToIns+#39+')';
end;
end;
end;
if (Tbl='Stoimost') then
begin
SelectQ := DataModule2.QSelUs;
pole1 := 'id';
pole2 := 'key_vid_uslug';
pole3 := 'key_ves';
pole4 := 'stoimost';
pole5 := '';
pole6 := '';
pole7 := '';
pole8 := '';
pole9 := '';
pole10 := '';
pole11 := '';
pole12 := '';
pole13 := '';
with SelectQ do
begin
First;
while (not Eof) do
begin
if (ForEdit <> SelectQ['ST.id']) then
begin
if ((SelectQ[pole2] = ToIns)and(SelectQ[pole3] = ToIns2)) then
begin
YN:=true;
Break;
end;
end;
Next;
end;
end;
if InsEdit2 then
begin
QueryString := 'UPDATE '+TBL+' SET '+pole2+'='+#39+ToIns+#39+','+pole3+'='+#39+ToIns2+#39+','+pole4+'='+#39+ToIns3+#39+' where '+pole1+'='+ForEdit;
InsEdit2 := false;
end
else
QueryString := 'insert into '+ TBL +' ('+pole2+','+pole3+','+pole4+') values ('+#39+ToIns+#39+','+#39+ToIns2+#39+','+#39+ToIns3+#39+')';
end;
if (Tbl='Vagon') then
begin
pole1 := 'id';
pole2 := 'mymonth';
pole3 := 'myyear';
pole4 := 'nomer_vagona';
pole5 := 'invent_nomer';
pole6 := 'year_izgot';
pole7 := 'gruzopodemnost';
pole8 := 'key_rod_vagona';
pole9 := 'iznos';
pole10 := 'key_raion_dvizh';
pole11 := '';
pole12 := '';
pole13 := '';
SelectQ := DataModule2.QShow;
with SelectQ do
begin
First;
while (not Eof) do
begin
if (ForEdit <> SelectQ['v.id']) then
begin
if (SelectQ[pole5] = ToIns4) then
begin
YN:=true;
Break;
end;
end;
Next;
end;
end;
if InsEdit3 then
begin
QueryString := 'UPDATE '+TBL+' SET '+pole2+'='+#39+ToIns+#39+','+pole3+'='+#39+ToIns2+#39+','+pole4+'='+#39+ToIns3+#39+','+pole5+'='+#39+ToIns4+#39+','+pole6+'='+#39+ToIns5+#39+','+pole7+'='+#39+ToIns6+#39+','+pole8+'='+#39+ToIns7+#39+','+pole9+'='+#39+ToIns8+#39+','+pole10+'='+#39+ToIns9+#39+' where '+pole1+'='+ForEdit;
InsEdit3 := false;
end
else
QueryString := 'insert into '+ TBL +' ('+pole2+', '+pole3+', '+pole4+', '+pole5+', '+pole6+', '+pole7+', '+pole8+', '+pole9+', '+pole10+') values ('+#39+ToIns+#39+', '+#39+ToIns2+#39+', '+#39+ToIns3+#39+', '+#39+ToIns4+#39+', '+#39+ToIns5+#39+', '+#39+ToIns6+#39+', '+#39+ToIns7+#39+', '+#39+ToIns8+#39+', '+#39+ToIns9+#39+')';
end;
if (Tbl='Operations_s_vagonom') then
begin
SelectQ := DataModule2.QOSV;
pole1 := 'id';
pole2 := 'key_station_otpr';
pole3 := 'key_front_otpr';
pole4 := 'key_station_naznach';
pole5 := 'key_front_naznach';
pole6 := 'mydate';
pole7 := 'mytime';
pole8 := 'key_operation';
pole9 := 'key_gruz';
pole10 := 'weight';
pole11 := 'n_dor_ved';
pole12 := 'n_ved';
pole13 := 'key_vagon';
with SelectQ do
begin
First;
while (not Eof) do
begin
if (ForEdit <> SelectQ['OSV.id']) then
begin
if ((SelectQ[pole11] = ToIns10)and(SelectQ[pole12] = ToIns11)) then
begin
YN:=true;
Break;
end;
end;
Next;
end;
end;
if InsEdit4 then
begin
QueryString := 'UPDATE '+TBL+' SET '+pole2+'='+#39+ToIns+#39+','+pole3+'='+#39+ToIns2+#39+','+pole4+'='+#39+ToIns3+#39+','+pole5+'='+#39+ToIns4+#39+','+pole6+'='+#39+ToIns5+#39+','+pole7+'='+#39+ToIns6+#39+','+pole8+'='+#39+ToIns7+#39+','+pole9+'='+#39+ToIns8+#39+','+pole10+'='+#39+ToIns9+#39+','+pole11+'='+#39+ToIns10+#39+','+pole12+'='+#39+ToIns11+#39+','+pole13+'='+#39+ToIns12+#39+' where '+pole1+'='+ForEdit;
InsEdit4 := false;
end
else
QueryString := 'insert into '+ TBL +' ('+pole2+', '+pole3+', '+pole4+', '+pole5+', '+pole6+', '+pole7+', '+pole8+', '+pole9+', '+pole10+', '+pole11+', '+pole12+', '+pole13+') values ('+#39+ToIns+#39+', '+#39+ToIns2+#39+', '+#39+ToIns3+#39+', '+#39+ToIns4+#39+', '+#39+ToIns5+#39+', '+#39+ToIns6+#39+', '+#39+ToIns7+#39+', '+#39+ToIns8+#39+', '+#39+ToIns9+#39+', '+#39+ToIns10+#39+', '+#39+ToIns11+#39+', '+#39+ToIns12+#39+')';
end;
if (Tbl='Uslugi_sv') then
begin
SelectQ := DataModule2.Quslugi;
pole1 := 'id';
pole2 := 'zakaz';
pole3 := 'key_vagon';
pole4 := 'key_uslugi';
pole5 := 'key_na';
pole6 := 'key_s';
pole7 := 'cena';
pole8 := '';
pole9 := '';
pole10 := '';
pole11 := '';
pole12 := '';
pole13 := '';
with SelectQ do
begin
First;
while (not Eof) do
begin
if (ForEdit <> SelectQ['USV.id']) then
begin
if (SelectQ[pole2] = ToIns) then
begin
YN:=true;
Break;
end;
end;
Next;
end;
end;
if InsEdit5 then