unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, ImgList, Menus, StdCtrls, Grids, DBGrids,
ExtCtrls, Spin;

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
Grid1: TStringGrid;
N9: TMenuItem;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Panel1: TPanel;
StatusBar1: TStatusBar;
Timer1: TTimer;
procedure N5Click(Sender: TObject);

procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure Button3Click(Sender: TObject);

procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Grid1KeyPress(Sender: TObject; var Key: Char);
procedure N8Click(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private

procedure lastsave();
{ Private declarations }
public
{ Public declarations }
end;

type list=record
name:string[20];
ball:extended;
income:integer;
end;
var
Form1: TForm1;
save: File of list;
item:list;
items: array [1..1000] of list;
filename:string;
n,i,k,m:integer;
bool:boolean;
minincome:integer;
quantity:integer;
implementation

{$R *.dfm}

procedure TForm1.N5Click(Sender: TObject);
begin
lastsave;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin

for i:=1 to grid1.rowCount do begin grid1.Cells[0,i]:='';
grid1.Cells[1,i]:='';
grid1.Cells[2,i]:='';
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
grid1.Cells[0,0]:='Фамилия'; // cells [столбец, строка]
grid1.Cells[1,0]:='Средний балл';
grid1.Cells[2,0]:='Доход на члена семьи';
bool:=false;
minincome:=spinedit1.Value;
quantity:=spinedit2.Value;
end;

procedure TForm1.N9Click(Sender: TObject);
begin
case grid1.Col of
0,1: begin grid1.col:=grid1.Col+1; grid1.Row:=grid1.Row; end;
2: begin grid1.rowCount:=grid1.rowCount+1; grid1.col:=0; grid1.Row:=grid1.Row+1; end;

end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin




for i:=1 to grid1.ColCount do begin grid1.Cells[0,i]:=items[i].name;
grid1.Cells[1,i]:=floattostr(items[i].ball);
grid1.Cells[2,i]:=inttostr(items[i].income);
end;
end;

procedure TForm1.N2Click(Sender: TObject);
begin
For i:=1 to grid1.rowCount+150 do begin
grid1.Cells[0,i]:='';
grid1.Cells[1,i]:='';
grid1.Cells[2,i]:='';
end;

grid1.rowCount:=2; ;
grid1.Color:=clWindow;
end;

procedure TForm1.N3Click(Sender: TObject);
begin
try
OpenDialog1.Title:='Открыть файл';
if OpenDialog1.Execute then
begin
AssignFile(save,OpenDialog1.FileName);
filename:=OpenDialog1.Filename;
statusbar1.SimpleText:='Текущий файл: '+filename+' '; timer1.Enabled:=true;
Reset(save);
end;
n:=0;
while not eof(save) do
begin
inc(n);
read(save,items[n]);
end;
closeFile(save);



grid1.rowCount:=n+1;

for i:=1 to n do begin grid1.Cells[0,i]:=items[i].name;
grid1.Cells[1,i]:=floattostr(items[i].ball);
grid1.Cells[2,i]:=inttostr(items[i].income);
end;




grid1.Color:=clWindow;
except
messagedlg('Ошибка при открытии файла',mtInformation,[mbOK],0);

end;


end;

procedure TForm1.N4Click(Sender: TObject);
begin
try
//сохранение//
for i:=1 to grid1.rowCount-1 do begin
items[i].name:=grid1.Cells[0,i];
items[i].ball:=strtofloat(grid1.Cells[1,i]);
items[i].income:=strtoint(grid1.Cells[2,i]);
end;




if SaveDialog1.Execute then
begin
assignfile(save, savedialog1.filename);
filename:=saveDialog1.FileName;
statusbar1.SimpleText:='Текущий файл: '+filename+' '; timer1.Enabled:=true;
rewrite(save);

end;
For i:=1 to grid1.rowCount-1 do write(save,items[i]);
closefile(save);



bool:=false;



except
messagedlg('Ошибка! Введены некорректные данные',mtInformation,[mbOK],0);
end;
end;


procedure TForm1.lastsave;
var a:word;
label lab, exit;
begin
IF bool=true then BEGIN

a:=messagedlg('Сохранить перед выходом не изволите?', mtConfirmation,[mbyes,mbno,mbcancel],0);
case a of
mryes: n4.Click;
mrno: application.Terminate;
mrcancel: goto lab;
end;
exit: application.terminate;
lab:application.Run;


END

ELSE application.Terminate;

end;

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

procedure TForm1.Grid1KeyPress(Sender: TObject; var Key: Char);
begin
bool:=true;
grid1.Color:=clWindow;
end;

procedure TForm1.N8Click(Sender: TObject);
var kol_vo:integer;
begin // сортировка //
try
kol_vo:=grid1.rowCount;

REPEAT

For i:=1 to grid1.rowCount-2 do
begin
If strtoint(grid1.Cells[2,i])> strtoint(grid1.cells[2,i+1]) Then
begin
item.income:=strtoint(grid1.Cells[2,i]);
item.name:=grid1.Cells[0,i];
item.ball:=strtofloat(grid1.Cells[1,i]);

grid1.Cells[2,i]:=grid1.cells[2,i+1];
grid1.Cells[0,i]:=grid1.cells[0,i+1];
grid1.Cells[1,i]:=grid1.cells[1,i+1];

grid1.cells[2,i+1]:=inttostr(item.income);
grid1.cells[0,i+1]:=item.name;
grid1.cells[1,i+1]:=floattostr(item.ball);
end;
end;
dec(kol_vo);
Until kol_vo=0;


/////////////// отсортировали по возрастанию дохода

for i:=1 to grid1.rowCount-1 do
If strtoint(grid1.Cells[2,i])<2*minincome then //grid1.fixedrows:=i+1
else begin
m:=i;
break;
end;

kol_vo:=grid1.rowCount;
REPEAT
For i:=m to grid1.rowCount-2 do
begin
If strtofloat(grid1.Cells[1,i])< strtofloat(grid1.cells[1,i+1]) Then
begin
item.income:=strtoint(grid1.Cells[2,i]);
item.name:=grid1.Cells[0,i];
item.ball:=strtofloat(grid1.Cells[1,i]);

grid1.Cells[2,i]:=grid1.cells[2,i+1];
grid1.Cells[0,i]:=grid1.cells[0,i+1];
grid1.Cells[1,i]:=grid1.cells[1,i+1];

grid1.cells[2,i+1]:=inttostr(item.income);
grid1.cells[0,i+1]:=item.name;
grid1.cells[1,i+1]:=floattostr(item.ball);
end;
end;
dec(kol_vo);
Until kol_vo=0;

// отсортировали по убыванию балла
// начало списка содержит людей, имеющих доход менее 2 мин. зарплат (в пор. возр. дохода
// продолжение списка - люди, имеющие доход свыше 2 мин. з/п, в пор. убывания балла
m:=grid1.rowCount;
IF quantity>grid1.rowCount-1 Then
else grid1.RowCount:=quantity+1;
grid1.Color:=2550255;


bool:=true;
except
messagedlg('Ошибка! Введены некорректные данные',mtInformation,[mbOK],0);




end;
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
try
minincome:=spinedit1.Value;
grid1.Color:=clWindow;
grid1.rowCount:=m;
except
spinedit1.Text:='1';
end;
end;

procedure TForm1.SpinEdit2Change(Sender: TObject);
begin
try
quantity:=spinedit2.Value;
grid1.Color:=clWindow;
grid1.rowCount:=m;
except
spinedit2.Text:='1';
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var aaa:string;
begin
If statusbar1.SimpleText<>'' Then begin
aaa:=statusbar1.SimpleText;
aaa:=aaa+copy(aaa,1,1);
delete(aaa,1,1);
statusbar1.SimpleText:=aaa; end
else
statusbar1.SimpleText:='Текущий файл: '+filename+' ';
end;

end.
Соседние файлы в папке Места в общаге