Смекни!
smekni.com

Кадровий облік (стр. 4 из 5)

var i,j: Integer;

A: Kadr;

begin

for i: =0 to WorkersCount-2 do

for j: =i+1 to WorkersCount-1 do

if Worker [i]. Experience>Worker [j]. Experience then begin

A: =Worker [i] ;

Worker [i]: =Worker [j] ;

Worker [j]: =A;

end;

Form1. RefreshList;

end;

procedure SortByLiberationData; // Сортування за датою звільнення

var i,j: Integer;

A: Kadr;

begin

for i: =0 to WorkersCount-2 do

for j: =i+1 to WorkersCount-1 do

if DataToInt(Worker [i]. LiberationData) >DataToInt(Worker [j]. LiberationData) then begin

A: =Worker [i] ;

Worker [i]: =Worker [j] ;

Worker [j]: =A;

end;

Form1. RefreshList;

end;

procedure SortByPositionName; // Сортування за назвою посади

var i,j: Integer;

A: Kadr;

begin

for i: =0 to WorkersCount-2 do

for j: =i+1 to WorkersCount-1 do

if Worker [i]. PositionName>Worker [j]. PositionName then begin

A: =Worker [i] ;

Worker [i]: =Worker [j] ;

Worker [j]: =A;

end;

Form1. RefreshList;

end;

procedure SortByDepartmentName; // Сортування за назвою відділу

var i,j: Integer;

A: Kadr;

begin

for i: =0 to WorkersCount-2 do

for j: =i+1 to WorkersCount-1 do

if Worker [i]. DepartmentName>Worker [j]. DepartmentName then begin

A: =Worker [i] ;

Worker [i]: =Worker [j] ;

Worker [j]: =A;

end;

Form1. RefreshList;

end;

procedure SortBySubsectionName; // Сортування за назвою підрозділу

var i,j: Integer;

A: Kadr;

begin

for i: =0 to WorkersCount-2 do

for j: =i+1 to WorkersCount-1 do

if Worker [i]. SubsectionName>Worker [j]. SubsectionName then begin

A: =Worker [i] ;

Worker [i]: =Worker [j] ;

Worker [j]: =A;

end;

Form1. RefreshList;

end;

procedure TForm1. ComboBox1Change(Sender: TObject);

begin

case ComboBox1. ItemIndex of

0: SortByTabN;

1: SortByLastName;

2: SortByName;

3: SortByPatronymic;

4: SortByBirdthDay;

5: SortByIndCode;

6: SortByReceptionData;

7: SortByExperience;

8: SortByLiberationData;

9: SortByPositionName;

10: SortByDepartmentName;

11: SortBySubsectionName;

end;

end;

procedure TForm1. CheckBox1Click(Sender: TObject);

var i: Integer;

begin

GroupBox4. Enabled: =CheckBox1. Checked;

Button1. Enabled: =not CheckBox1. Checked;

Button3. Enabled: =not CheckBox1. Checked;

if CheckBox1. Checked then begin

RezervCount: =WorkersCount;

SetLength(Rezerv,RezervCount);

for i: =0 to RezervCount-1 do

Rezerv [i]: =Worker [i] ;

end else begin

WorkersCount: =RezervCount;

SetLength(Worker,WorkersCount);

for i: =0 to WorkersCount-1 do

Worker [i]: =Rezerv [i] ;

RefreshList;

end;

end;

procedure TForm1. Button7Click(Sender: TObject);

var i: Integer;

begin

WorkersCount: =RezervCount;

SetLength(Worker,WorkersCount);

for i: =0 to WorkersCount-1 do

Worker [i]: =Rezerv [i] ;

RefreshList;

end;

procedure TForm1. ComboBox3KeyPress(Sender: TObject; var Key: Char);

begin

case ComboBox2. ItemIndex of

0,4,7,8,9,11: if not (Key in ['0'. '9',#8]) then Key: =#0;

6,10,12,13,14,15,16: Key: =#0;

end;

end;

procedure TForm1. ComboBox3Change(Sender: TObject);

begin

if ComboBox2. ItemIndex in [4,8,11] then

if Length(ComboBox3. Text) in [2,5] then begin

ComboBox3. Text: =ComboBox3. Text+'. ';

ComboBox3. SelStart: =Length(ComboBox3. Text);

end;

end;

procedure TForm1. ComboBox2Change(Sender: TObject);

begin

ComboBox3. Clear;

ComboBox3. MaxLength: =0;

case ComboBox2. ItemIndex of

0: ComboBox3. MaxLength: =5;

4,7,8,11: ComboBox3. MaxLength: =10;

9: ComboBox3. MaxLength: =2;

6: ComboBox3. Items: =Form2. ComboBox1. Items;

12: ComboBox3. Items: =Form2. ComboBox4. Items;

13: ComboBox3. Items: =Form2. ComboBox3. Items;

14: ComboBox3. Items: =Form2. ComboBox2. Items;

10,15,16: begin

ComboBox3. Items. Add('Ні');

ComboBox3. Items. Add('Так');

end;

end;

end;

procedure TForm1. ComboBox2KeyPress(Sender: TObject; var Key: Char);

begin

Key: =#0;

end;

function TForm1. FindInRec(Index: Integer): Integer;

var i: Integer;

begin

Result: =-1;

for i: =0 to RezervCount-1 do

if Worker [Index]. TabN=Rezerv [i]. TabN then begin

Result: =i;

Exit;

end;

end;

procedure FindByTabN;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. TabN<>Form2. STI(Form1. ComboBox3. Text) then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByLastName;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. LastName<>Form1. ComboBox3. Text then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByName;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. Name<>Form1. ComboBox3. Text then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByPatronymic;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. Patronymic<>Form1. ComboBox3. Text then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByBirthDay;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if DataToInt(Worker [i]. BirthData) <>

DataToInt(Form1. GetData(Form1. ComboBox3. Text)) then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByBirthPlace;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. BirthPlace<>Form1. ComboBox3. Text then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByStat;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if ORD(Worker [i]. Stat) <>Form1. ComboBox3. ItemIndex then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByIndCode;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. IndCode<>Form1. ComboBox3. Text then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByReceptionData;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if DataToInt(Worker [i]. ReceptionData) <>

DataToInt(Form1. GetData(Form1. ComboBox3. Text)) then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByExperience;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if Worker [i]. Experience<>Form2. STI(Form1. ComboBox3. Text) then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByExempt;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if ORD(Worker [i]. Exempt) <>Form1. ComboBox3. ItemIndex then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByLiberationData;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if DataToInt(Worker [i]. LiberationData) <>

DataToInt(Form1. GetData(Form1. ComboBox3. Text)) then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByPositionName;

var i,j: Integer;

begin

i: =0;

j: =Form1. ComboBox3. ItemIndex;

if j<0 then Exit;

while i<=WorkersCount-1 do begin

if Worker [i]. PositionName<>Form1. ComboBox3. Items. Strings [j] then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByDepartmentName;

var i,j: Integer;

begin

i: =0;

j: =Form1. ComboBox3. ItemIndex;

if j<0 then Exit;

while i<=WorkersCount-1 do begin

if Worker [i]. DepartmentName<>Form1. ComboBox3. Items. Strings [j] then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindBySubsectionName;

var i,j: Integer;

begin

i: =0;

j: =Form1. ComboBox3. ItemIndex;

if j<0 then Exit;

while i<=WorkersCount-1 do begin

if Worker [i]. SubsectionName<>Form1. ComboBox3. Items. Strings [j] then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindByDepartmentLeader;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if ORD(Worker [i]. DepartmentLeader) <>Form1. ComboBox3. ItemIndex then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure FindBySubsectionLeader;

var i: Integer;

begin

i: =0;

while i<=WorkersCount-1 do begin

if ORD(Worker [i]. SubsectionLeader) <>Form1. ComboBox3. ItemIndex then begin

Form2. DelWorker(i);

DEC(i);

end;

INC(i);

end;

Form1. RefreshList;

end;

procedure TForm1. Button6Click(Sender: TObject);

begin

case ComboBox2. ItemIndex of

0: FindByTabN;

1: FindByLastName;

2: FindByName;

3: FindByPatronymic;

4: FindByBirthDay;

5: FindByBirthPlace;

6: FindByStat;

7: FindByIndCode;

8: FindByReceptionData;

9: FindByExperience;

10: FindByExempt;

11: FindByLiberationData;

12: FindByPositionName;

13: FindByDepartmentName;

14: FindBySubsectionName;

15: FindByDepartmentLeader;

16: FindBySubsectionLeader;

end;

end;

end.

unit WorkerUnit;

interface

uses

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

Dialogs, StdCtrls, Mask, ExtCtrls;

type

TForm2 = class(TForm)

Button1: TButton;

Button2: TButton;

Label12: TLabel;

CheckBox3: TCheckBox;

Edit8: TEdit;

Panel1: TPanel;

Label9: TLabel;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Label8: TLabel;

Label10: TLabel;

Label11: TLabel;

Label13: TLabel;

Label14: TLabel;

Edit1: TEdit;

Edit2: TEdit;

Edit3: TEdit;

Edit4: TEdit;

Edit5: TEdit;

ComboBox1: TComboBox;

Edit6: TEdit;

ComboBox2: TComboBox;

CheckBox1: TCheckBox;

ComboBox3: TComboBox;

CheckBox2: TCheckBox;

ComboBox4: TComboBox;

Edit7: TEdit;

Edit9: TEdit;

Edit10: TEdit;

Button3: TButton;

function STI(S: String): Integer;

procedure ClearField;

procedure FormToRec(Index: Integer);

procedure ClearWorker(Index: Integer);

procedure DelWorker(Index: Integer);

procedure Edit7KeyPress(Sender: TObject; var Key: Char);

procedure FormShow(Sender: TObject);

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

procedure ComboBox2KeyPress(Sender: TObject; var Key: Char);

procedure RecToForm(Index: Integer);

function Verification: Boolean;

procedure Button1Click(Sender: TObject);

procedure CheckBox3Click(Sender: TObject);

procedure Edit7Change(Sender: TObject);

procedure Edit8Change(Sender: TObject);

procedure Edit10Change(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Edit1KeyPress(Sender: TObject; var Key: Char);

procedure Button3Click(Sender: TObject);

procedure ComboBox2DropDown(Sender: TObject);

procedure ComboBox3DropDown(Sender: TObject);

procedure ComboBox4DropDown(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

OK: Boolean=False;

implementation

uses KadrUnit, RegUnit;

{$R *. dfm}

function TForm2. STI(S: String): Integer;

var E: Integer;

begin

/ / Ця функція альтернативна StrToInt, тільки при помилці результат = 0

Val(S,Result,E);

if E<>0 then Result: =0;

end;

function SUB_Data(A,B: Data): Integer;

var A1,B1: Integer;

begin

A1: =A. Y*365+A. M*31+A. D;

B1: =B. Y*365+B. M*31+B. D;

Result: =Trunc((A1-B1) / 365);

end;

procedure TForm2. ClearField;

begin

Edit1. Text: =''; Edit2. Text: ='';

Edit3. Text: =''; Edit4. Text: ='';

Edit5. Text: =''; Edit6. Text: ='';

Edit7. Text: =''; Edit8. Text: ='';

Edit9. Text: =''; Edit10. Text: ='';

CheckBox1. Checked: =False;

CheckBox2. Checked: =False;

CheckBox3. Checked: =False;

ComboBox1. ItemIndex: =-1; ComboBox2. ItemIndex: =-1;

ComboBox3. ItemIndex: =-1; ComboBox4. ItemIndex: =-1;

end;

procedure TForm2. FormToRec(Index: Integer);

begin

if ((Index>=WorkersCount) or(Index<0)) then Exit;

Worker [Index]. TabN: =STI(Edit1. Text);

Worker [Index]. LastName: =Edit3. Text;

Worker [Index]. Name: =Edit4. Text;

Worker [Index]. Patronymic: =Edit5. Text;

Worker [Index]. BirthData: =Form1. GetData(Edit7. Text);

Worker [Index]. BirthPlace: =Edit6. Text;

if ComboBox1. ItemIndex>=0 then

Worker [Index]. Stat: =Boolean(ComboBox1. ItemIndex);

Worker [Index]. IndCode: =Edit2. Text;

Worker [Index]. ReceptionData: =Form1. GetData(Edit10. Text);

Worker [Index]. Experience: =STI(Edit9. Text);

Worker [Index]. Exempt: =CheckBox3. Checked;

if CheckBox3. Checked then

Worker [Index]. LiberationData: =Form1. GetData(Edit8. Text);

if ComboBox4. ItemIndex>=0 then

Worker [Index]. PositionName: =ComboBox4. Items. Strings [ComboBox4. ItemIndex] ;

if ComboBox3. ItemIndex>=0 then

Worker [Index]. DepartmentName: =ComboBox3. Items. Strings [ComboBox3. ItemIndex] ;

Worker [Index]. DepartmentLeader: =CheckBox2. Checked;

if ComboBox2. ItemIndex>=0 then

Worker [Index]. SubsectionName: =ComboBox2. Items. Strings [ComboBox2. ItemIndex] ;

Worker [Index]. SubsectionLeader: =CheckBox1. Checked;

end;

function ItemIndex(S: String; ST: TStrings): Integer;

var i: Integer;

begin

Result: =-1;

for i: =0 to ST. Count-1 do

if ST. Strings [i] =S then begin

Result: =i;

Exit;

end;

end;

procedure TForm2. RecToForm(Index: Integer);

begin

if ((Index>=WorkersCount) or(Index<0)) then Exit;

Edit1. Text: =IntToStr(Worker [Index]. TabN);

Edit3. Text: =Worker [Index]. LastName;

Edit4. Text: =Worker [Index]. Name;

Edit5. Text: =Worker [Index]. Patronymic;

Edit7. Text: =Form1. DataToStr(Worker [Index]. BirthData);

Edit6. Text: =Worker [Index]. BirthPlace;

ComboBox1. ItemIndex: =Ord(Worker [Index]. Stat);

Edit2. Text: =Worker [Index]. IndCode;

Edit10. Text: =Form1. DataToStr(Worker [Index]. ReceptionData);

Edit9. Text: =IntToStr(Worker [Index]. Experience);

CheckBox3. Checked: =Worker [Index]. Exempt;

Edit8. Enabled: =CheckBox3. Checked;

if CheckBox3. Checked then

Edit8. Text: =Form1. DataToStr(Worker [Index]. LiberationData);

ComboBox4. ItemIndex: =ItemIndex(Worker [Index]. PositionName,ComboBox4. Items);

ComboBox3. ItemIndex: =ItemIndex(Worker [Index]. DepartmentName,ComboBox3. Items);

CheckBox2. Checked: =Worker [Index]. DepartmentLeader;

ComboBox2. ItemIndex: =ItemIndex(Worker [Index]. SubsectionName,ComboBox2. Items);