Смекни!
smekni.com

Разработка программного комплекса (стр. 2 из 2)

procedure GridDeleteRow(RowNumber: Integer; Grid: TstringGrid);

var

i: Integer;

begin

Grid.Row := RowNumber;

if (Grid.Row = Grid.RowCount - 1) then

{ On the last row}

Grid.RowCount := Grid.RowCount - 1

else

begin

{ Not the last row}

for i := RowNumber to Grid.RowCount - 1 do

Grid.Rows[i] := Grid.Rows[i + 1];

Grid.RowCount := Grid.RowCount - 1;

end;

end;

//Удалениестрок

procedure TForm1.Button5Click(Sender: TObject);

var

i,n,start:integer;

begin

n := StringGrid1.Selection.Bottom - StringGrid1.Selection.Top + 1;

start:= StringGrid1.Selection.Top;

ifStringGrid1.Selection.Bottom < StringGrid1.Selection.Top then

start:= StringGrid1.Selection.Bottom;

for i := 1 to n do

begin

GridDeleteRow(start + i - 1, StringGrid1);

end;

end;

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

var

res:integer;

begin

if Base = '' then

begin

res := MessageDlg('Сохранитьзаписи?',mtInformation,[mbYes, mbNo],0);

if res = mrYes then

SetBase()

else

exit;

end;

WriteData(Base, StringGrid1);

end;

//записьданныхвфайлбазы

//fileName - имя и путь к файлу базы

//table - Таблицасданными

procedure TForm1.WriteData(fileName:string; table:TStringGrid);

var

F:File of TWorker;

i:integer;

begin

AssignFile(F,fileName);

Reset(F);

Seek(F,0);

for i := 1 to table.RowCount-2 do

begin

TableRowToWorker(i,StringGrid1);

Write(F,Worker);

end;

CloseFile(F);

end;

//Функция быстрой сортировки

//А - массив для сортировки

//iLo - начало массива

//iHi - конецмассива

procedure QuickSort(var A: array of TWorker; iLo, iHi: Integer);

var

Lo, Hi: Integer;

Pivot :TDate;

T: TWorker;

begin

Lo := iLo;

Hi := iHi;

Pivot := A[(Lo + Hi) div 2].BirthDay;

repeat

while A[Lo].BirthDay < Pivot do Inc(Lo) ;

while A[Hi].BirthDay > Pivot do Dec(Hi) ;

if Lo <= Hi then

begin

T := A[Lo];

A[Lo] := A[Hi];

A[Hi] := T;

Inc(Lo) ;

Dec(Hi) ;

end;

until Lo > Hi;

if Hi > iLo then QuickSort(A, iLo, Hi) ;

if Lo < iHi then QuickSort(A, Lo, iHi) ;

end;

//Выполняетзапросы

procedure TForm1.Button3Click(Sender: TObject);

var

i:integer;

Workers:array of TWorker;

y1,m1,d1,y2,m2,d2:Word;

MAge, WAge : real;

MStch, WStch : integer;

begin

if ComboBox1.ItemIndex = 0 then

begin

SetLength(Workers, StringGrid1.RowCount - 2);

DecodeDate(Now,y2,m2,d2);

for i := 1 to StringGrid1.RowCount - 2 do

begin

TableRowToWorker(i,StringGrid1);

DecodeDate(Worker.BirthDay,y1,m1,d1);

if (abs(y2 - y1) <= 30) and (Worker.sex = 0) then

Workers[i-1] :=Worker;

end;

Form4.FillTable(Workers);

Form4.ShowModal;

end

else

if ComboBox1.ItemIndex = 1 then

begin

DecodeDate(Now,y2,m2,d2);

MStch := 0;

WStch := 0;

for i := 1 to StringGrid1.RowCount - 2 do

begin

TableRowToWorker(i,StringGrid1);

DecodeDate(Worker.BirthDay,y1,m1,d1);

if (Worker.sex = 0) then

begin

MAge := MAge + y2 - y1;

MStch := MStch +1;

end

else

begin

WAge := WAge + y2 - y1;

WStch := WStch +1;

end;

end;

MAge := MAge / MStch;

WAge := WAge / WStch;

Form5.Label3.Caption := FloatToStrF(MAge,ffGeneral, 8, 2);

Form5.Label4.Caption := FloatToStrF(WAge,ffGeneral, 8, 2);

Form5.ShowModal;

end

else

if ComboBox1.ItemIndex = 2 then

begin

SetLength(Workers, StringGrid1.RowCount - 1);

DecodeDate(Now,y2,m2,d2);

for i := 1 to StringGrid1.RowCount - 2 do

begin

TableRowToWorker(i,StringGrid1);

DecodeDate(Worker.StartWork,y1,m1,d1);

if y2 = y1 then

Workers[i] :=Worker;

end;

if (Length(Workers) > 3) then

QuickSort(Workers,1, Length(Workers))

else

if Workers[1].BirthDay < Workers[1].BirthDay then

begin

worker :=Workers[1];

Workers[1] := Workers[2];

Workers[2] := worker;

end;

Form6.FillTable(Workers);

Form6.ShowModal;

end

else

if ComboBox1.ItemIndex = 3 then

begin

SetLength(Workers, StringGrid1.RowCount - 2);

for i := 1 to StringGrid1.RowCount - 2 do

begin

TableRowToWorker(i,StringGrid1);

Workers[i-1] :=Worker;

end;

Form7.FillTable(Workers);

Form7.ShowModal;

end

else

if ComboBox1.ItemIndex = 4 then

begin

SetLength(Workers, StringGrid1.RowCount - 2);

for i := 1 to StringGrid1.RowCount - 2 do

begin

TableRowToWorker(i,StringGrid1);

Workers[i-1] :=Worker;

end;

Form7.FillKrug(Workers);

Form7.ShowModal;

end

else

if ComboBox1.ItemIndex = 5 then

begin

SetLength(Workers, StringGrid1.RowCount - 2);

for i := 1 to StringGrid1.RowCount - 2 do

begin

TableRowToWorker(i,StringGrid1);

Workers[i-1] :=Worker;

end;

Form7.FillStolb(Workers);

Form7.ShowModal;

end;

end;

procedure TForm1.FormShow(Sender: TObject);

begin

StringGrid1.Cells[0,0] := 'Фамилия';

StringGrid1.Cells[1,0] := 'Принят';

StringGrid1.Cells[2,0] := 'Образование';

StringGrid1.Cells[3,0] := 'Специализация';

StringGrid1.Cells[4,0] := 'Пол';

StringGrid1.Cells[5,0] := 'Отн. кслужбе';

StringGrid1.Cells[6,0] := 'Датарождения';

end;

end.

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm2 = class(TForm)

RadioButton1: TRadioButton;

RadioButton2: TRadioButton;

Edit1: TEdit;

Label1: TLabel;

Label3: TLabel;

Edit3: TEdit;

Button1: TButton;

Button2: TButton;

Button3: TButton;

OpenDialog1: TOpenDialog;

SaveDialog1: TSaveDialog;

procedure RadioButton1Click(Sender: TObject);

procedure RadioButton2Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.RadioButton1Click(Sender: TObject);

begin

Label1.Enabled := true;

Edit1.Enabled := true;

Edit3.Enabled := false;

Label3.Enabled := false;

Button2.Enabled := true;

Button3.Enabled := false;

end;

procedure TForm2.RadioButton2Click(Sender: TObject);

begin

Label1.Enabled := false;

Edit1.Enabled := false;

Button2.Enabled := false;

Edit3.Enabled := true;

Label3.Enabled := true;

Button3.Enabled := true;

end;

procedure TForm2.Button2Click(Sender: TObject);

begin

if SaveDialog1.Execute then

begin

Edit1.Text := SaveDialog1.FileName+'.txt';

end

end;

procedure TForm2.Button3Click(Sender: TObject);

begin

if OpenDialog1.Execute then

begin

Edit3.Text := OpenDialog1.FileName;

end;

end;

procedure TForm2.Button1Click(Sender: TObject);

begin

ModalResult := mrOk;

//Close;

end;

end.

unit Unit3;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ComCtrls, Unit1;

type

TForm3 = class(TForm)

Label1: TLabel;

Edit1: TEdit;

Label2: TLabel;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

ComboBox1: TComboBox;

Edit2: TEdit;

ComboBox2: TComboBox;

Edit3: TEdit;

DateTimePicker1: TDateTimePicker;

DateTimePicker2: TDateTimePicker;

Button1: TButton;

Button2: TButton;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure ClearFields();

procedure FormShow(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

Worker:TWorker;

editRecord:bool;

end;

var

Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.ClearFields();

begin

Edit1.Text := '';

DateTimePicker2.Date := Now;

ComboBox1.ItemIndex := 0;

Edit2.Text := '';

ComboBox2.ItemIndex := 0;

Edit3.Text := '';

DateTimePicker1.Date := Now;

end;

procedure TForm3.Button1Click(Sender: TObject);

begin

Worker.FIO := Edit1.Text;

Worker.StartWork := DateTimePicker2.Date;

Worker.Edication := ComboBox1.Text;

Worker.Spec := Edit2.Text;

Worker.sex := ComboBox2.ItemIndex;

Worker.Armi := Edit3.Text;

Worker.BirthDay := DateTimePicker1.Date;

ModalResult := mrOK;

end;

procedure TForm3.Button2Click(Sender: TObject);

begin

ModalResult := mrCancel;

end;

procedure TForm3.FormShow(Sender: TObject);

begin

if not editRecord then

ClearFields

else

begin

Edit1.Text := Worker.FIO;

DateTimePicker2.Date := Worker.StartWork;

ComboBox1.Text := Worker.Edication;

Edit2.Text := Worker.Spec;

ComboBox2.ItemIndex := Worker.sex;

Edit3.Text := Worker.Armi;

DateTimePicker1.Date := Worker.BirthDay;

end;

end;

end.

unit Unit4;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids, Unit1;

type

TForm4 = class(TForm)

StringGrid1: TStringGrid;

private

{ Private declarations }

public

{ Public declarations }

procedure FillTable(Workers:array of TWorker);

end;

var

Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.FillTable(Workers:array of TWorker);

var

i,n:integer;

begin

n:= Length(Workers);

StringGrid1.Cells[0,0] := 'Фамилия';

StringGrid1.Cells[1,0] := 'Образование';

StringGrid1.Cells[2,0] := 'Отношение к службе';

StringGrid1.RowCount := n+1;

for i:=1 to n do

begin

StringGrid1.Cells[0,i] := Workers[i-1].FIO;

StringGrid1.Cells[1,i] := Workers[i-1].Edication;

StringGrid1.Cells[2,i] := Workers[i-1].Armi;

end;

end;

end.

unit Unit6;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids, Unit1;

type

TForm6 = class(TForm)

StringGrid1: TStringGrid;

private

{ Private declarations }

public

procedure FillTable(Workers:array of TWorker);

{ Public declarations }

end;

var

Form6: TForm6;

implementation

{$R *.dfm}

procedure TForm6.FillTable(Workers:array of TWorker);

var

i,n:integer;

begin

n:= Length(Workers);

StringGrid1.Cells[0,0] := 'Фамилия';

StringGrid1.Cells[1,0] := 'Датарожд.';

StringGrid1.RowCount := n;

for i:=1 to n-1 do

begin

StringGrid1.Cells[0,i] := Workers[i].FIO;

StringGrid1.Cells[1,i] := DateToStr(Workers[i].BirthDay);

end;

end;

end.

unit Unit7;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, TeEngine, TeeFunci, Series, ExtCtrls, TeeProcs, Chart, Unit1;

type

TForm7 = class(TForm)

Chart1: TChart;

Series1: TLineSeries;

TeeFunction1: TMultiplyTeeFunction;

Chart2: TChart;

Series3: TPieSeries;

Chart3: TChart;

Series2: TBarSeries;

private

{ Private declarations }

public

{ Public declarations }

procedure FillTable(Workers:array of TWorker);

procedure FillKrug(Workers:array of TWorker);

procedure FillStolb(Workers:array of TWorker);

end;

var

Form7: TForm7;

implementation

{$R *.dfm}

procedure TForm7.FillTable(Workers:array of TWorker);

var

i,n:integer;

y1,m1,d1,y2,m2,d2:Word;

yars:array[0..60] of integer;

begin

//Chart1.SeriesList.Clear;

//Chart1.SeriesList.Add(Series1);

Chart1.Visible := true;

Chart2.Visible := false;

Chart3.Visible := false;

Caption := 'Образование';

Series1.Clear;

n:= Length(Workers);

DecodeDate(Now,y2,m2,d2);

for i:=1 to 60 do

yars[i-1] := 0;

for i:=1 to n do

begin

DecodeDate(Workers[i-1].BirthDay,y1,m1,d1);

if (Workers[i-1].Edication = 'Высшее') then

yars[y2-y1] := yars[y2-y1] + 5

else

if (Workers[i-1].Edication = 'Cреднеспециальное') then

yars[y2-y1] := yars[y2-y1] + 4

else

if (Workers[i-1].Edication = 'Cреднее') then

yars[y2-y1] := yars[y2-y1] + 3

else

if (Workers[i-1].Edication = 'Неполноесреднее') then

yars[y2-y1] := yars[y2-y1] + 2

else

yars[y2-y1] := yars[y2-y1] + 1;

end;

for i:=1 to 60 do

Series1.AddXY(i,yars[i-1]);

end;

procedure TForm7.FillKrug(Workers:array of TWorker);

var

i,n : integer;

y1,m1,d1,y2,m2,d2 : Word;

stch1,stch2,stch3 : integer;

begin

//Chart1.SeriesList.Clear;

//Chart1.SeriesList.Clear;

//Chart1.SeriesList.Add(Series2);

Chart1.Visible := false;

Chart2.Visible := true;

Chart3.Visible := false;

Caption := 'Возрастноесоотношение';

Series3.Clear;

stch1 := 0;

stch2 := 0;

stch3 := 0;

n:= Length(Workers);

DecodeDate(Now,y2,m2,d2);

for i:=1 to n do

begin

DecodeDate(Workers[i-1].BirthDay,y1,m1,d1);

if (y2-y1 <= 30) then

Inc(stch1)

else

if (y2-y1 <= 50) then

Inc(stch2)

else

Inc(stch3);

end;

//Series2.Add(50);

Series3.Add(stch1);

Series3.Add(stch2);

Series3.Add(stch3);

end;

procedure TForm7.FillStolb(Workers:array of TWorker);

var

i,n : integer;

stch1,stch2,stch3,stch4,stch5 : integer;

begin

Chart1.Visible := false;

Chart2.Visible := false;

Chart3.Visible := true;

Caption := 'Образованиесотрудников';

Series2.Clear;

stch1 := 0;

stch2 := 0;

stch3 := 0;

stch4 := 0;

stch5 := 0;

n:= Length(Workers);

for i:=1 to n do

begin

if (Workers[i-1].Edication = 'Высшее') then

Inc(stch1)

else

if (Workers[i-1].Edication = 'Cреднеспециальное') then

Inc(stch2)

else

if (Workers[i-1].Edication = 'Cреднее') then

Inc(stch3)

else

if (Workers[i-1].Edication = 'Неполноесреднее') then

Inc(stch4)

else

Inc(stch5);

end;

Series2.Add(stch1);

Series2.Add(stch2);

Series2.Add(stch3);

Series2.Add(stch4);

Series2.Add(stch5);

end;

end.