Скачиваний:
9
Добавлен:
17.06.2023
Размер:
1.8 Mб
Скачать

DM.ADOQuery8.Open;

DM.ADOQuery8.Locate('soed.s_id',d,[]);

end;

key:=dm.SotrQuery.Fields[0].AsInteger;

DM.ADOQuery8.SQL.Clear;

DM.ADOQuery8.SQL.Add('select * from sotr, audit, soed where sotr.s_id = soed.s_id and audit.a_id = soed.a_id and sotr.s_id=:PARAM');

DM.ADOQuery8.Parameters.ParamByName('PARAM').V alue:=key;

DM.ADOQuery8.Open;

end;

procedure TFrmSotr.N1Click(Sender: TObject);

begin

OpenForm(false);

Refresh;

end;

procedure TFrmSotr.N2Click(Sender: TObject);

begin

Refresh;

if DM.SotrQuery.FieldValues['edit']=false then

begin

OpenForm(true);

Refresh;

end

else

MessageDlg('Запись редактируется другим пользователем',mtError,[mbOK],0);

end;

procedure TFrmSotr.N3Click(Sender: TObject);

begin

Refresh;

if DM.SotrQuery.FieldValues['edit']=false then

begin

if MessageDlg('Удалить запись?',mtWarning,[mbYes,mbNo],0)=mrYes then//если "да"

begin DM.SotrQuery.Delete; Refresh;

end; end else

MessageDlg('Запись редактируется другим пользователем',mtError,[mbOK],0);

end;

procedure TFrmSotr.FormShow(Sender: TObject); begin

if chek='Пользователь' then begin

N1.Enabled:=false;

N2.Enabled:=false;

end;

if chek='Гость' then begin N1.Enabled:=false; N2.Enabled:=false; N3.Enabled:=false; end;

end;

procedure TFrmSotr.DBGrid1CellClick(Column: TColumn);

begin key:=dm.SotrQuery.Fields[0].AsInteger; DM.ADOQuery8.SQL.Clear;

52

DM.ADOQuery8.SQL.Add('select * from sotr, audit, soed where sotr.s_id = soed.s_id and audit.a_id = soed.a_id and sotr.s_id=:PARAM');

DM.ADOQuery8.Parameters.ParamByName('PARAM').V alue:=key;

DM.ADOQuery8.Open;

end;

procedure TFrmSotr.DBGrid1KeyUp(Sender: TObject; var Key: Word;

Shift: TShiftState);

begin

key:=dm.SotrQuery.Fields[0].AsInteger;

DM.ADOQuery8.SQL.Clear;

DM.ADOQuery8.SQL.Add('select * from sotr, audit, soed where sotr.s_id = soed.s_id and audit.a_id = soed.a_id and sotr.s_id=:PARAM');

DM.ADOQuery8.Parameters.ParamByName('PARAM').V alue:=key;

DM.ADOQuery8.Open;

end;

end.

unit Otchet1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes,

Graphics, Controls, Forms,

Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DBCtrls;

type

TFrmOtchet1 = class(TForm)

DBGrid1: TDBGrid;

DBLookupComboBox1: TDBLookupComboBox;

Label1: TLabel;

procedure DBLookupComboBox1CloseUp(Sender: TObject);

procedure FormCreate(Sender: TObject);

private

{Private declarations } public

{Public declarations } end;

var

FrmOtchet1: TFrmOtchet1;

implementation

uses DataModule, Oborud;

{$R *.dfm}

procedure TFrmOtchet1.DBLookupComboBox1CloseUp(Sender: TObject);

begin

DM.ADOQuery3.SQL.Clear;

DM.ADOQuery3.SQL.Add('select a_nomer from Zakrep_oborud z, oborud, audit where (o_id=z_o_id) and (a_id=z_a_id) and (o_id='+FloatToStr(DBLookupComboBox1.keyvalue)+');' );

DM.ADOQuery3.Open;

end;

procedure TFrmOtchet1.FormCreate(Sender: TObject);

begin

DM.ADOConnection.Connected:=true;

DM.OborudQuery.SQL.Clear;

53

DM.OborudQuery.SQL.Add(oborud_SQL+';');

DM.OborudQuery.Open;

end;

end.

unit Otchet2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes,

Graphics, Controls, Forms,

Dialogs, StdCtrls, DBCtrls, ExtCtrls, Grids, DBGrids,

Menus, ComObj;

type

TFrmOtchet2 = class(TForm)

DBGrid1: TDBGrid;

DBLookupComboBox1: TDBLookupComboBox;

Label1: TLabel;

PopupMenu1: TPopupMenu;

Excel1: TMenuItem;

procedure DBLookupComboBox1CloseUp(Sender: TObject);

procedure FormCreate(Sender: TObject); procedure Excel1Click(Sender: TObject); private

{Private declarations } public

{Public declarations } end;

var

FrmOtchet2: TFrmOtchet2;

implementation

uses DataModule, Sotr;

{$R *.dfm}

procedure TFrmOtchet2.DBLookupComboBox1CloseUp(Sender: TObject);

begin

DM.ADOQuery5.SQL.Clear;

DM.ADOQuery5.SQL.Add('select o_name, o_inv_nomer from Zakrep_oborud ,audit, oborud, sotr, soed where (o_id=z_o_id) and (sotr.s_id=soed.s_id) and (audit.a_id=soed.a_id) and (audit.a_id=z_a_id) and (sotr.s_id='+FloatToStr(DBLookupComboBox1.keyvalue) +');');

DM.ADOQuery5.Open;

end;

procedure TFrmOtchet2.FormCreate(Sender: TObject);

begin

DM.ADOConnection.Connected:=true;

DM.SotrQuery.SQL.Clear;

DM.SotrQuery.SQL.Add(sotr_SQL+';');

DM.SotrQuery.Open;

end;

procedure TFrmOtchet2.Excel1Click(Sender: TObject);

var

i,j,index,count: Integer;

ExcelApp,sheet: oleVariant;

begin

ExcelApp := CreateOleObject('Excel.Application');

ExcelApp.WorkBooks.Add(-4167);

ExcelApp.Worksheets[1].PageSetup.Orientation := 1;

54

ExcelApp.WorkBooks[1].WorkSheets[1].name := 'Список оборудования';

ExcelApp.WorkBooks[1].WorkSheets[1].Columns[1].Col umnWidth := 30;

ExcelApp.WorkBooks[1].WorkSheets[1].Columns[2].Col umnWidth := 20;

sheet:=ExcelApp.WorkBooks[1].WorkSheets['Список оборудования'];

sheet.Range[sheet.Cells[1, 1], sheet.Cells[1,2]].Select; ExcelApp.Selection.MergeCells:=True; ExcelApp.Selection.HorizontalAlignment:=3; ExcelApp.Selection.Borders.Weight:=4; sheet.Range['A1']:= 'Список оборудования'; index:=2;

count := dm.ADOQuery5.Fields.Count ; for i := 1 to count do

begin

sheet.cells[index,i]:=dm.ADOQuery5.Fields[i- 1].DisplayLabel;

sheet.Cells[index,i].Select;

ExcelApp.Selection.Borders.Weight:=4;

end;

inc(index);

DBGrid1.DataSource.DataSet.First;

for i:=1 to DBGrid1.DataSource.DataSet.RecordCount do begin

for j:=1 to DBGrid1.FieldCount do begin

sheet.cells[index,j]:=DBGrid1.fields[j-1].asstring; sheet.Cells[index,j].Select; ExcelApp.Selection.Borders.Weight:=4;

end;

inc(index);

DBGrid1.DataSource.DataSet.Next;

end;

ExcelApp.Visible := true; end;

end.

unit Otchet3;

interface

uses

Windows, Messages, SysUtils, Variants, Classes,

Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TFrmOtchet3 = class(TForm)

Label1: TLabel;

Label2: TLabel;

Button1: TButton;

procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private

{Private declarations } public

{Public declarations } end;

var

FrmOtchet3: TFrmOtchet3; a: string;

implementation

uses DataModule;

55

{$R *.dfm}

private

 

{ Private declarations }

procedure TFrmOtchet3.FormCreate(Sender: TObject);

public

begin

{ Public declarations }

DM.ADOConnection.Connected:=true;

end;

DM.ADOQuery7.SQL.Clear;

 

DM.ADOQuery7.SQL.Text:='Select * FROM

var

[Запрос2]';

FrmOtchet4: TFrmOtchet4;

DM.ADOQuery7.Open;

 

end;

implementation

 

procedure TFrmOtchet3.Button1Click(Sender: TObject);

uses DataModule;

begin

 

a:=DM.ADOQuery7.Fields[0].asString;

{$R *.dfm}

label2.Caption:=a;

 

end;

procedure TFrmOtchet4.FormCreate(Sender: TObject);

 

end.

begin

DM.ADOConnection.Connected:=true;

unit Otchet4;

end;

 

interface

procedure TFrmOtchet4.Button1Click(Sender: TObject);

 

uses

begin

DM.ADOQuery4.SQL.Clear;

Windows, Messages, SysUtils, Variants, Classes,

DM.ADOQuery4.SQL.Add('select o_name, o_inv_nomer

Graphics, Controls, Forms,

Dialogs, Mask, DBCtrls, StdCtrls, ExtCtrls, Grids,

from Zakrep_oborud , oborud, audit where (o_id=z_o_id)

and (a_id=z_a_id) and

DBGrids;

(a_nomer="'+LabeledEdit1.Text+'");');

 

DM.ADOQuery4.Open;

type

end;

TFrmOtchet4 = class(TForm)

 

DBGrid1: TDBGrid;

end.

LabeledEdit1: TLabeledEdit;

unit Otchet5;

Button1: TButton;

 

procedure FormCreate(Sender: TObject);

interface

procedure Button1Click(Sender: TObject);

 

 

56

uses

Windows, Messages, SysUtils, Variants, Classes,

Graphics, Controls, Forms,

Dialogs, StdCtrls, Grids, DBGrids, ComObj, OleServer,

Excel2000;

type

TFrmOtchet5 = class(TForm)

DBGrid1: TDBGrid;

Button1: TButton;

Button2: TButton;

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{Private declarations } public

{Public declarations } end;

var

FrmOtchet5: TFrmOtchet5;

implementation

uses DataModule;

{$R *.dfm}

procedure TFrmOtchet5.Button1Click(Sender: TObject);

begin

DM.ADOQuery6.SQL.Clear;

DM.ADOQuery6.SQL.Add('Select a_nomer, o_name, o_inv_nomer from zakrep_oborud, audit, oborud where (z_a_id=a_id) and (z_o_id=o_id)');

DM.ADOQuery6.Open;

end;

procedure TFrmOtchet5.FormCreate(Sender: TObject); begin

DM.ADOConnection.Connected:=true;

end;

procedure TFrmOtchet5.Button2Click(Sender: TObject); var

i,j,index,count: Integer; ExcelApp,sheet: oleVariant; begin

try

ExcelApp := CreateOleObject('Excel.Application'); except

ShowMessage('Не удалось запустить Excel.');

Exit;

end; try

ExcelApp.WorkBooks.Add(-4167);

ExcelApp.Worksheets[1].PageSetup.Orientation := 1;

ExcelApp.WorkBooks[1].WorkSheets[1].name := 'Перечень всех аудиторий';

ExcelApp.WorkBooks[1].WorkSheets[1].Columns[1].Col umnWidth := 20;

ExcelApp.WorkBooks[1].WorkSheets[1].Columns[2].Col umnWidth := 30;

ExcelApp.WorkBooks[1].WorkSheets[1].Columns[3].Col umnWidth := 20;

sheet:=ExcelApp.WorkBooks[1].WorkSheets['Перечень всех аудиторий'];

sheet.Range[sheet.Cells[1, 1], sheet.Cells[1,3]].Select;

ExcelApp.Selection.MergeCells:=True;

57

ExcelApp.Selection.HorizontalAlignment:=3;

ExcelApp.Selection.Borders.Weight:=4;

sheet.Range['A1']:= 'Перечень всех аудиторий с закрепленными за ними оборудованием';

index:=2;

count := dm.ADOQuery6.Fields.Count ; for i := 1 to count do

begin

sheet.cells[index,i]:=dm.ADOQuery6.Fields[i- 1].DisplayLabel;

sheet.Cells[index,i].Select;

ExcelApp.Selection.Borders.Weight:=4;

end;

inc(index);

DBGrid1.DataSource.DataSet.First;

for i:=1 to DBGrid1.DataSource.DataSet.RecordCount do begin

for j:=1 to DBGrid1.FieldCount do begin

sheet.cells[index,j]:=DBGrid1.fields[j-1].asstring; sheet.Cells[index,j].Select; ExcelApp.Selection.Borders.Weight:=4;

end;

inc(index);

DBGrid1.DataSource.DataSet.Next;

end;

ExcelApp.Visible := true; ExcelApp.DisplayAlerts := False; ExcelApp.Dialogs.Item[8].Show finally

if not VarIsEmpty(ExcelApp) then begin

ExcelApp.Quit;

ExcelApp := Unassigned;

end;

end;

end;

end.

unit EditZakrepOborud;

interface

uses

Windows, Messages, SysUtils, Variants, Classes,

Graphics, Controls, Forms,

Dialogs, StdCtrls, DBCtrls, Mask, Grids, DBGrids;

type

TFrmEditZakrepOborud = class(TForm)

Button1: TButton;

Button2: TButton;

DBLookupComboBox1: TDBLookupComboBox;

DBLookupComboBox2: TDBLookupComboBox;

Label1: TLabel;

Label2: TLabel;

procedure FormClose(Sender: TObject; var Action: TCloseAction);

procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private

{Private declarations } public

{Public declarations } end;

procedure openform(ed:boolean);

var

FrmEditZakrepOborud: TFrmEditZakrepOborud;

a,b :string;

58

implementation

uses DataModule;

{$R *.dfm}

procedure openform(ed:boolean);

begin

if ed then

begin

FrmEditZakrepOborud.Caption:='Измененние';

DM.ADOQuery1.Edit;

DM.ADOQuery1.FieldValues['edit']:=true;

DM.ADOQuery1.Post;

DM.ADOQuery1.Edit;

DM.ADOQuery9.SQL.Clear;

DM.ADOQuery9.SQL.Add('select s_fam from soed, sotr, audit, Zakrep_oborud where z_a_id=audit.a_id and audit.a_id=soed.a_id and soed.s_id=sotr.s_id and z_id=:PARAM');

DM.ADOQuery9.Parameters.ParamByName('PARAM').V alue:=dm.Zakrep_oborudQuery.Fields[0].AsInteger;

DM.ADOQuery9.Open;

end

else

begin

FrmEditZakrepOborud.Caption:='Добавление';

DM.ADOQuery1.Append;

end;

FrmEditZakrepOborud.ShowModal;

end;

procedure TFrmEditZakrepOborud.FormClose(Sender: TObject;

var Action: TCloseAction);

begin

DM.ADOQuery1.Cancel;

DM.ADOQuery1.Edit;

dm.ADOQuery1.FieldValues['edit']:=false;

DM.ADOQuery1.Post;

end;

procedure TFrmEditZakrepOborud.Button2Click(Sender: TObject);

begin

DM.ADOQuery1.Cancel;

DM.ADOQuery1.Edit;

dm.ADOQuery1.FieldValues['edit']:=false;

DM.ADOQuery1.Post;

FrmEditZakrepOborud.Close;

end;

procedure TFrmEditZakrepOborud.Button1Click(Sender: TObject);

begin

if (dblookupcombobox1.Text='') or (dblookupcombobox2.Text='') then

begin

MessageDlg('Введите все данные!',mtError,[mbOk],0);

Abort;

end;

dm.ADOQuery1.FieldValues['edit']:=false;

DM.ADOQuery1.Post;

DM.ADOQuery9.SQL.Clear;

DM.ADOQuery9.SQL.Add('select s_fam from soed, sotr, audit, Zakrep_oborud where z_a_id=audit.a_id and audit.a_id=soed.a_id and soed.s_id=sotr.s_id and z_id=:PARAM');

DM.ADOQuery9.Parameters.ParamByName('PARAM').V alue:=dm.Zakrep_oborudQuery.Fields[0].AsInteger;

DM.ADOQuery9.Open;

59

FrmEditZakrepOborud.Close;

procedure FormClose(Sender: TObject; var Action:

end;

TCloseAction);

procedure Button2Click(Sender: TObject);

 

end.

procedure Button1Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

unit EditSotr;

procedure FormShow(Sender: TObject);

 

interface

procedure Button4Click(Sender: TObject);

private

 

uses

{ Private declarations }

public

Windows, Messages, SysUtils, Variants, Classes,

 

Graphics, Controls, Forms,

{ Public declarations }

Dialogs, StdCtrls, DBCtrls, Mask, ExtCtrls, Grids,

end;

DBGrids;

procedure openform(ed:boolean);

 

type

var

FrmEditSotr: TFrmEditSotr;

TFrmEditSotr = class(TForm)

yes, yes1, no, no1:boolean;

Button1: TButton;

count, count1: integer;

Button2: TButton;

 

DBEdit1: TDBEdit;

implementation

DBEdit2: TDBEdit;

 

DBEdit3: TDBEdit;

uses DataModule, Sotr;

DBEdit5: TDBEdit;

 

DBEdit6: TDBEdit;

{$R *.dfm}

Label1: TLabel;

procedure openform(ed:boolean);

Label2: TLabel;

begin

Label3: TLabel;

if ed then

Label5: TLabel;

begin

Label6: TLabel;

FrmEditSotr.Caption:='Измененние';

Button3: TButton;

DM.SotrQuery.Edit;

Button4: TButton;

DM.SotrQuery.FieldValues['edit']:=true;

DBListBox1: TDBListBox;

DM.SotrQuery.Post;

DBListBox2: TDBListBox;

DM.SotrQuery.Edit;

Label4: TLabel;

FrmEditSotr.DBListBox1.Items.clear;

Label7: TLabel;

FrmEditSotr.DBListBox2.Items.clear;

 

60

DM.ADOQuery12.SQL.Clear;

DM.ADOQuery12.SQL.Add('select audit.a_nomer from sotr, audit, soed where sotr.s_id = soed.s_id and audit.a_id = soed.a_id and sotr.s_id=:PARAM');

DM.ADOQuery12.Parameters.ParamByName('PARAM').

Value:=dm.SotrQuery.Fields[0].AsInteger;

DM.ADOQuery12.Open;

dm.ADOQuery12.First;

while not dm.ADOQuery12.Eof do

begin

FrmEditSotr.DBListBox1.Items.Add(dm.ADOQuery12.Fi eldValues['a_nomer']);

dm.ADOQuery12.Next;

end;

DM.ADOQuery11.SQL.Clear;

DM.ADOQuery11.SQL.Add('select a_nomer from audit');

DM.ADOQuery11.Open;

dm.ADOQuery11.First;

while not dm.ADOQuery11.Eof do

begin

FrmEditSotr.DBListBox2.Items.Add(dm.ADOQuery11.Fi eldValues['a_nomer']);

dm.ADOQuery11.Next;

end;

yes:=false;

yes1:=false;

no:=false;

no1:=false;

count:=0;

count1:=0;

end

else

begin

FrmEditSotr.Caption:='Добавление';

DM.SotrQuery.Append;

FrmEditSotr.DBListBox1.Items.clear;

FrmEditSotr.DBListBox2.Items.clear;

DM.ADOQuery11.SQL.Clear;

DM.ADOQuery11.SQL.Add('select a_nomer from audit');

DM.ADOQuery11.Open;

dm.ADOQuery11.First;

while not dm.ADOQuery11.Eof do begin

FrmEditSotr.DBListBox2.Items.Add(dm.ADOQuery11.Fi eldValues['a_nomer']);

dm.ADOQuery11.Next;

end;

yes:=false;

yes1:=false;

no:=false;

no1:=false;

end;

FrmEditSotr.ShowModal;

end;

procedure TFrmEditSotr.FormClose(Sender: TObject; var Action: TCloseAction);

begin

if no1=true then dm.ADOQuery10.Cancel; if no=true then

begin

if yes=false then dm.AdoQuery10.Connection.BeginTrans; DM.ADOQuery10.Connection.RollbackTrans; end;

DM.SotrQuery.Edit;

61

Соседние файлы в папке Курсовые работы