, . , .
. , . .
, :
-
-
-
-
-
-
-
-
1.
6
CD/DVD . : (, , ..), , , ( .. ). :
- ( );
- , ;
- , , .
2.
.
2.1 .
(), , ().
, .. , , .
, .. .
. , .
.. , , .
|
|
, , .. , .
, , .
.
, , , () / .
( ).
, , .
, .. , . , , , .
, .
.
, , .
, .. Delphi .
, , .
, .. , .
, .. .
, , .. . , .
2.4 .
, , , .
. , .. .
.
Head | PDisk | PDisk | ... | PDisk |
Data |
Name |
Author |
Price |
Note |
Data |
Name |
Author |
Price |
Note |
Data |
Name |
Author |
Price |
Note |
2.1
|
|
CD/DVD , PDisk. .
3.
CD/DVD .
:
- CD/DVD (, , , , );
- CD/DVD ;
- CD/DVD ;
- CD/DVD ;
- CD/DVD ;
- CD/DVD ;
- CD/DVD ;
- CD/DVD .
, .
3.1
3.2
3.3
3.4
3.5
3.6
3.7
4.
1) Delphi: TLabel, TEdit, TCombobox, TButton, TBitBtn, TRadioGroup, TStringGrid, TPanel.
2) , .
3) PDisk , .. .
4 ( , , '''' ''''), .
5) .
:
procedure TFrmMain.BtnDeleteClick(Sender: TObject);
var
H, Temp: PDisk;
begin
H:= Head;
if Sg.Row <> 0 then
begin
if (H^.Data = Sg.Cells[0, Sg.Row]) and
(H^.Name = Sg.Cells[1, Sg.Row]) and
(H^.Author = Sg.Cells[2, Sg.Row]) and
(inttostr(H^.Price) = Sg.Cells[3, Sg.Row]) and
(H^.Note = Sg.Cells[4, Sg.Row]) then
begin
Temp:= Head;
Head:= Head^.Next;
Dispose (Temp);
end
else
begin
while (H^.Next^.Data <> Sg.Cells[0, Sg.Row]) or
(H^.Next^.Name <> Sg.Cells[1, Sg.Row]) or
(H^.Next^.Author <> Sg.Cells[2, Sg.Row]) or
(inttostr(H^.Next^.Price) <> Sg.Cells[3, Sg.Row]) or
(H^.Next^.Note <> Sg.Cells[4, Sg.Row]) do
H:= H^.Next;
Temp:= H^.Next;
H^.Next:= H^.Next^.Next;
Dispose (Temp);
end;
GridDeleteRow(Sg.Row);
end;
end;
5.
5.1 -
AddNewDisk | . | , . | : ; ; _; 25000; | , , , . |
: ; Total commander; Cristian_ Ghistler; 50000; - | , , , .. , . | |||
ChangeDisk | . | , . | : ; -; _; 30000; | , , . |
: ; ; _; 25000; | , , , .. , . | |||
DeleteDisk | . | . | : ; ; _; 25000; | . |
SearchByName | . | , . | : | , , , . |
: | , , , , .. , . | |||
SortByName | . | . |
6.
|
|
( 6.1).
6.1
, , . , ( 6.2).
6.2
:
1.
2.
3.
4.
5.
"" , ( 6.3) "".
6.3
:
1) , ; , ( 6.4):
6.4
2) , "" ""( 6.5):
6.5
3) ():
6.6
, , "" , ( 6.7) "".
6.7
, .
"" ( 6.8).
6.8
( 6.9) "ok" (). ""( 6.10).
|
|
6.9
6.10
( 6.11):
6.11
(6.12).
6.12
, . .
7.
, , .
( ), . , Delphi, . , .
, ( ) , . . .
, . .
.
, , 1 .
8.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Grids, Vcl.Buttons, unit2;
type
PDisk = ^Disk;
Disk = Record
Data: string;
Name: string;
Author: string;
Price: integer;
Note: string;
Next: PDisk;
End;
TFrmMain = class(TForm)
Sg: TStringGrid;
PnlActions: TPanel;
BtnAdd: TButton;
BtnChange: TButton;
BtnDelete: TButton;
EdtAuthorSearch: TEdit;
BtnNameSearch: TButton;
EdtNameSearch: TEdit;
BtnAuthorSearch: TButton;
Rg: TRadioGroup;
LblSearch: TLabel;
LblOperations: TLabel;
PnlOperations: TPanel;
PnlSearch: TPanel;
BtnRefresh: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BtnAddClick(Sender: TObject);
procedure BtnChangeClick(Sender: TObject);
procedure BtnDeleteClick(Sender: TObject);
procedure BtnNameSearchClick(Sender: TObject);
procedure BtnRefreshClick(Sender: TObject);
procedure BtnAuthorSearchClick(Sender: TObject);
procedure RgClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SgDrawCell(Sender: TObject; ACol, ARow: integer; Rect: TRect;
State: TGridDrawState);
private
{ Private declarations }
public
procedure Sort(SortType: integer);
{ Public declarations }
end;
var
FrmMain: TFrmMain;
Head: PDisk;
Correct: Boolean = true;
IsAdded: Boolean;
implementation
{$R *.dfm}
//
procedure TFrmMain.Sort(SortType: integer);
var
H, N, NewHead, Temp: PDisk;
DiskType, NewDiskType, RowNum, ColNum: integer;
CurName, NewName: String;
begin
H:= Head;
NewHead:= nil;
// ,
while H <> nil do
begin
// DiskType -
if H^.Data = '' then
DiskType:= 0
else if H^.Data = '' then
DiskType:= 1
else
DiskType:= 2;
// ,
if NewHead = nil then
begin
New(NewHead);
NewHead^:= H^;
NewHead^.Next:= nil;
end
else
//
begin
N:= NewHead;
// NewDiskType -
if N^.Data = '' then
NewDiskType:= 0
else if N^.Data = '' then
NewDiskType:= 1
else
NewDiskType:= 2;
{ 1
,
}
if (DiskType > NewDiskType) and (NewHead^.Next = nil) then
|
|
begin
New(N^.Next);
N^.Next^:= H^;
N^.Next^.Next:= nil;
end
else
//
begin
// DiskType = NewDiskType, .. 1
if NewHead^.Next = nil then
begin
{ SortType = 0, , 1 - .
CurName NewName - , ,
(0) (1) , CurName - ,
NewName - }
if SortType = 0 then
begin
CurName:= H^.Name;
NewName:= N^.Name;
end
else
begin
CurName:= H^.Author;
NewName:= N^.Author;
end;
// ()
if AnsiLowerCase(CurName) > AnsiLowerCase(NewName) then
begin
New(NewHead^.Next);
NewHead^.Next^:= H^;
NewHead^.Next^.Next:= nil;
end
else
begin
Temp:= NewHead;
New(NewHead);
NewHead^:= H^;
NewHead^.Next:= Temp;
end;
end
// , 1
else
begin
//
if N^.Data = '' then
NewDiskType:= 0
else if N^.Data = '' then
NewDiskType:= 1
else
NewDiskType:= 2;
if SortType = 0 then
begin
CurName:= H^.Name;
NewName:= N^.Name;
end
else
begin
CurName:= H^.Author;
NewName:= N^.Author;
end;
// 1
if (DiskType = NewDiskType) and
(AnsiLowerCase(CurName) < AnsiLowerCase(NewName)) then
begin
Temp:= NewHead;
New(NewHead);
NewHead^:= H^;
NewHead^.Next:= Temp;
end
else
//
begin
repeat
// ,
if N^.Next = nil then
begin
New(N^.Next);
N^.Next^:= H^;
N^.Next^.Next:= nil;
break;
end;
//
if SortType = 0 then
begin
CurName:= H^.Name;
NewName:= N^.Next^.Name;
end
else
begin
CurName:= H^.Author;
NewName:= N^.Next^.Author;
end;
{ (
() )
(
), }
if ((DiskType = NewDiskType) and
(AnsiLowerCase(CurName) > AnsiLowerCase(NewName))) or
(DiskType > NewDiskType) then
begin
N:= N^.Next;
if N^.Next <> nil then
begin
if N^.Next^.Data = '' then
NewDiskType:= 0
else if N^.Next^.Data = '' then
NewDiskType:= 1
else
NewDiskType:= 2;
end;
end
else
{ , (
() )
(
), }
begin
Temp:= N^.Next;
New(N^.Next);
N^.Next^:= H^;
N^.Next^.Next:= Temp;
break;
end;
// ,
until N = nil;
end;
end;
end;
end;
// ()
H:= H^.Next;
{ ,
, ,
( ) }
end;
if Head <> nil then
begin
while Head <> nil do
begin
Temp:= Head;
Head:= Head^.Next;
Dispose(Temp);
end;
Head:= NewHead;
//
if IsAdded = true then
Sg.RowCount:= Sg.RowCount + 1;
H:= Head;
with FrmMain do
for RowNum:= 1 to Sg.RowCount - 1 do
begin
for ColNum:= 0 to 4 do
begin
case ColNum of
0:
Sg.Cells[ColNum, RowNum]:= H^.Data;
1:
Sg.Cells[ColNum, RowNum]:= H^.Name;
2:
Sg.Cells[ColNum, RowNum]:= H^.Author;
3:
Sg.Cells[ColNum, RowNum]:= inttostr(H^.Price);
4:
Sg.Cells[ColNum, RowNum]:= H^.Note;
end;
end;
H:= H^.Next;
end;
end;
end;
// ''
procedure TFrmMain.BtnAddClick(Sender: TObject);
begin
with FrmNewDisk do
begin
//
CmbDiskType.ItemIndex:= 0;
EdtName.Text:= '';
EdtAuthor.Text:= '';
EdtPrice.Text:= '';
EdtNote.Text:= '';
BtnAddNewDisk.Visible:= true;
BtnChangeDisk.Visible:= false;
IsAdded:= true;
//
FrmNewDisk.ShowModal;
end;
end;
//
procedure PrintSearch(Searching: string; T: integer);
var
H, Temp, PrintDisk: PDisk;
Comparing: string;
begin
with FrmNewDisk do
with FrmMain do
begin
// PrintDisk - ,
PrintDisk:= nil;
H:= Head;
//
while H <> nil do
begin
{ T , = 1,
, .
Comparing - / ,
Searching - /, }
if T = 1 then
Comparing:= H^.Name
else
Comparing:= H^.Author;
// Searching / Comparing
if Pos(AnsiLowerCase(Searching), AnsiLowerCase(Comparing)) <> 0 then
begin
// PrintDisk , 1 ()
if PrintDisk = nil then
begin
New(PrintDisk);
PrintDisk^:= H^;
PrintDisk^.Next:= nil;
end
else
// ,
begin
Temp:= PrintDisk;
while Temp^.Next <> nil do
Temp:= Temp^.Next;
New(Temp^.Next);
Temp^.Next^:= H^;
Temp^.Next^.Next:= nil;
end;
end;
// ()
H:= H^.Next;
end;
{ , , PrintDisk ,
}
if PrintDisk = nil then
ShowMessage(' .')
else
begin
{ PrintDisk , ,
PrintDisk'a
( ) }
Sg.RowCount:= 1;
while PrintDisk <> nil do
begin
Sg.RowCount:= Sg.RowCount + 1;
Sg.Cells[0, Sg.RowCount - 1]:= PrintDisk^.Data;
Sg.Cells[1, Sg.RowCount - 1]:= PrintDisk^.Name;
Sg.Cells[2, Sg.RowCount - 1]:= PrintDisk^.Author;
Sg.Cells[3, Sg.RowCount - 1]:= inttostr(PrintDisk^.Price);
Sg.Cells[4, Sg.RowCount - 1]:= PrintDisk^.Note;
Temp:= PrintDisk;
PrintDisk:= PrintDisk^.Next;
Dispose(Temp);
end;
end;
end;
end;
// ,
procedure TFrmMain.BtnAuthorSearchClick(Sender: TObject);
begin
PrintSearch(EdtAuthorSearch.Text, 2);
end;
// ''
procedure TFrmMain.BtnChangeClick(Sender: TObject);
var
H, Temp: PDisk;
RowNum, ColNum: integer;
begin
with FrmNewDisk do
begin
//
if Sg.Row <> 0 then
begin
{
() }
if Sg.Cells[0, Sg.Row] = '' then
CmbDiskType.ItemIndex:= 0;
if Sg.Cells[0, Sg.Row] = '' then
CmbDiskType.ItemIndex:= 1;
if Sg.Cells[0, Sg.Row] = '' then
CmbDiskType.ItemIndex:= 2;
EdtName.Text:= Sg.Cells[1, Sg.Row];
EdtAuthor.Text:= Sg.Cells[2, Sg.Row];
EdtPrice.Text:= Sg.Cells[3, Sg.Row];
EdtNote.Text:= Sg.Cells[4, Sg.Row];
BtnAddNewDisk.Visible:= false;
BtnChangeDisk.Visible:= true;
Correct:= false;
//
FrmNewDisk.ShowModal;
// ,
if Correct = false then
begin
Exit;
end
else
//
begin
H:= Head;
// 1 (1 )}
if Sg.Row = 1 then
begin
// ''
if CmbDiskType.Text = '' then
begin
H^.Data:= CmbDiskType.Text;
H^.Name:= EdtName.Text;
H^.Author:= EdtAuthor.Text;
H^.Price:= strtoint(EdtPrice.Text);
H^.Note:= EdtNote.Text;
{ ,
1 }
if Rg.ItemIndex = -1 then
begin
Sg.Cells[0, 1]:= CmbDiskType.Text;
Sg.Cells[1, 1]:= EdtName.Text;
Sg.Cells[2, 1]:= EdtAuthor.Text;
Sg.Cells[3, 1]:= EdtPrice.Text;
Sg.Cells[4, 1]:= EdtNote.Text;
ShowMessage(' .');
Exit;
end;
end;
// ''
if CmbDiskType.Text = '' then
begin
// Temp ,
Temp:= H;
H:= H^.Next;
Head:= Head^.Next;
Temp^.Data:= CmbDiskType.Text;
Temp^.Name:= EdtName.Text;
Temp^.Author:= EdtAuthor.Text;
Temp^.Price:= strtoint(EdtPrice.Text);
Temp^.Note:= EdtNote.Text;
{ () '',
Temp 1 }
if H^.Data = '' then
begin
Temp^.Next:= H;
Head:= Temp;
end
else
//
begin
//
if H^.Next <> nil then
// '' ''
while (H^.Next^.Data <> '') and
(H^.Next^.Data <> '') do
begin
{ ,
}
if H^.Next^.Next <> nil then
H:= H^.Next
else
//
begin
H:= H^.Next;
break;
end;
end;
// Temp
Temp^.Next:= H^.Next;
H^.Next:= Temp;
end;
end;
// ''
if CmbDiskType.Text = '' then
begin
// Temp ,
Temp:= H;
H:= H^.Next;
Head:= Head^.Next;
Temp^.Data:= CmbDiskType.Text;
Temp^.Name:= EdtName.Text;
Temp^.Author:= EdtAuthor.Text;
Temp^.Price:= strtoint(EdtPrice.Text);
Temp^.Note:= EdtNote.Text;
{ () '',
Temp 1 }
if Head^.Data = '' then
begin
Temp^.Next:= Head;
Head:= Temp;
end
else
//
begin
//
if H^.Next <> nil then
// ''
while H^.Next^.Data <> '' do
begin
{ ,
}
if H^.Next^.Next <> nil then
H:= H^.Next
else
//
begin
H:= H^.Next;
break;
end;
end;
// Temp
Temp^.Next:= H^.Next;
H^.Next:= Temp;
end;
end;
end
else
// 1 ( 1 )}
begin
// Temp ,
while (H^.Next^.Data <> Sg.Cells[0, Sg.Row]) or
(H^.Next^.Name <> Sg.Cells[1, Sg.Row]) or
(H^.Next^.Author <> Sg.Cells[2, Sg.Row]) or
(inttostr(H^.Next^.Price) <> Sg.Cells[3, Sg.Row]) or
(H^.Next^.Note <> Sg.Cells[4, Sg.Row]) do
H:= H^.Next;
Temp:= H^.Next;
H^.Next:= H^.Next^.Next;
Temp^.Data:= CmbDiskType.Text;
Temp^.Name:= EdtName.Text;
Temp^.Author:= EdtAuthor.Text;
Temp^.Price:= strtoint(EdtPrice.Text);
Temp^.Note:= EdtNote.Text;
//
// ''
if CmbDiskType.Text = '' then
begin
Temp^.Next:= Head;
Head:= Temp;
end;
// ''
if CmbDiskType.Text = '' then
begin
H:= Head;
{ () '',
Temp 1 }
if Head^.Data = '' then
begin
Temp^.Next:= Head;
Head:= Temp;
end
else
//
begin
//
if H^.Next <> nil then
// '' ''
while (H^.Next^.Data <> '') and
(H^.Next^.Data <> '') do
begin
{ ,
}
if H^.Next^.Next <> nil then
H:= H^.Next
else
//
begin
H:= H^.Next;
break;
end;
end;
// Temp
Temp^.Next:= H^.Next;
H^.Next:= Temp;
end;
end;
// ''
if CmbDiskType.Text = '' then
begin
H:= Head;
{ () '',
Temp 1 }
if Head^.Data = '' then
begin
Temp^.Next:= Head;
Head:= Temp;
end
else
//
begin
//
if H^.Next <> nil then
// ''
while H^.Next^.Data <> '' do
begin
{ ,
}
if H^.Next^.Next <> nil then
H:= H^.Next
else
//
begin
H:= H^.Next;
break;
end;
end;
// Temp
Temp^.Next:= H^.Next;
H^.Next:= Temp;
end;
end;
end;
{ ,
}
if Rg.ItemIndex = 0 then
begin
IsAdded:= false;
Sort(0);
ShowMessage(' .');
Exit;
end;
{ ,
}
if Rg.ItemIndex = 1 then
begin
IsAdded:= false;
Sort(1);
ShowMessage(' .');
Exit;
end;
// ,
H:= Head;
for RowNum:= 1 to Sg.RowCount - 1 do
begin
for ColNum:= 0 to 4 do
begin
case ColNum of
0:
Sg.Cells[ColNum, RowNum]:= H^.Data;
1:
Sg.Cells[ColNum, RowNum]:= H^.Name;
2:
Sg.Cells[ColNum, RowNum]:= H^.Author;
3:
Sg.Cells[ColNum, RowNum]:= inttostr(H^.Price);
4:
Sg.Cells[ColNum, RowNum]:= H^.Note;
end;
end;
H:= H^.Next;
end;
ShowMessage(' .');
end;
end;
end;
end;
//
procedure GridDeleteRow(RowNumber: integer);
var
i: integer;
begin
with FrmMain do
begin
Sg.Row:= RowNumber;
//
if Sg.Row = Sg.RowCount - 1 then
Sg.RowCount:= Sg.RowCount - 1
else
begin
//
for i:= RowNumber to Sg.RowCount - 1 do
Sg.Rows[i]:= Sg.Rows[i + 1];
Sg.RowCount:= Sg.RowCount - 1;
end;
end;
end;
// ''
procedure TFrmMain.BtnDeleteClick(Sender: TObject);
var
H, Temp: PDisk;
begin
H:= Head;
//
if Sg.Row <> 0 then
begin
{
, () ,
}
if (H^.Data = Sg.Cells[0, Sg.Row]) and (H^.Name = Sg.Cells[1, Sg.Row]) and
(H^.Author = Sg.Cells[2, Sg.Row]) and
(inttostr(H^.Price) = Sg.Cells[3, Sg.Row]) and
(H^.Note = Sg.Cells[4, Sg.Row]) then
begin
Temp:= Head;
Head:= Head^.Next;
Dispose(Temp);
end
else
{
, ()
}
begin
while (H^.Next^.Data <> Sg.Cells[0, Sg.Row]) or
(H^.Next^.Name <> Sg.Cells[1, Sg.Row]) or
(H^.Next^.Author <> Sg.Cells[2, Sg.Row]) or
(inttostr(H^.Next^.Price) <> Sg.Cells[3, Sg.Row]) or
(H^.Next^.Note <> Sg.Cells[4, Sg.Row]) do
H:= H^.Next;
Temp:= H^.Next;
H^.Next:= H^.Next^.Next;
Dispose(Temp);
end;
// ()
GridDeleteRow(Sg.Row);
end;
end;
// ,
procedure TFrmMain.BtnNameSearchClick(Sender: TObject);
begin
PrintSearch(EdtNameSearch.Text, 1);
end;
{ '' ,
}
procedure TFrmMain.BtnRefreshClick(Sender: TObject);
var
H: PDisk;
begin
H:= Head;
Sg.RowCount:= 1;
while H <> nil do
begin
Sg.RowCount:= Sg.RowCount + 1;
Sg.Cells[0, Sg.RowCount - 1]:= H^.Data;
Sg.Cells[1, Sg.RowCount - 1]:= H^.Name;
Sg.Cells[2, Sg.RowCount - 1]:= H^.Author;
Sg.Cells[3, Sg.RowCount - 1]:= inttostr(H^.Price);
Sg.Cells[4, Sg.RowCount - 1]:= H^.Note;
H:= H^.Next;
end;
EdtNameSearch.Text:= '';
EdtAuthorSearch.Text:= '';
end;
//
procedure TFrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
var
F: TextFile;
begin
AssignFile(F, 'Data.txt');
if Head <> nil then
begin
//
Rewrite(F);
//
while Head <> nil do
begin
//
if Head^.Data = '' then
write(F, '0 ')
else if Head^.Data = '' then
write(F, '1 ')
else
write(F, '2 ');
write(F, Head^.Name, ' ');
write(F, Head^.Author, ' ');
write(F, inttostr(Head^.Price), ' ');
{ , ('') }
if Head^.Next = nil then
write(F, Head^.Note)
else
{ ,
('') }
writeln(F, Head^.Note);
//
Head:= Head^.Next;
end;
//
CloseFile(F);
end
else if FileExists('Data.txt') then
Erase(F);
end;
//
procedure TFrmMain.FormCreate(Sender: TObject);
var
F: TextFile;
C: char;
S: string;
H: PDisk;
i: integer;
begin
{ ,
}
Sg.ColWidths[1]:= 250;
Sg.ColWidths[2]:= 150;
Sg.ColWidths[4]:= 495;
Sg.Cells[0, 0]:= ' ';
Sg.Cells[1, 0]:= ' ';
Sg.Cells[2, 0]:= ' ';
Sg.Cells[3, 0]:= ' ';
Sg.Cells[4, 0]:=
' ';
//
if FileExists('Data.txt') then
begin
// F
AssignFile(F, 'Data.txt');
Reset(F);
// i -
i:= 1;
//
while not Eof(F) do
begin
//
if Head = nil then
begin
// ,
New(Head);
Read(F, C);
case strtoint(C) of
0:
Head^.Data:= '';
1:
Head^.Data:= '';
2:
Head^.Data:= '';
end;
Read(F, C, C);
S:= '';
while C <> ' ' do
begin
S:= S + C;
Read(F, C);
end;
Head^.Name:= S;
S:= '';
Read(F, C);
while C <> ' ' do
begin
S:= S + C;
Read(F, C);
end;
Head^.Author:= S;
S:= '';
Read(F, C);
while C <> ' ' do
begin
S:= S + C;
Read(F, C);
end;
Head^.Price:= strtoint(S);
S:= '';
Read(F, C);
while not((Ord(C) = 13) or (Ord(C) = 26)) do
begin
S:= S + C;
Read(F, C);
end;
Head^.Note:= S;
Head^.Next:= nil;
// ( )
Sg.RowCount:= Sg.RowCount + 1;
Sg.Cells[0, 1]:= Head^.Data;
Sg.Cells[1, 1]:= Head^.Name;
Sg.Cells[2, 1]:= Head^.Author;
Sg.Cells[3, 1]:= inttostr(Head^.Price);
Sg.Cells[4, 1]:= Head^.Note;
end
else
//
begin
// ,
Readln(F);
H:= Head;
while H^.Next <> nil do
H:= H^.Next;
New(H^.Next);
H:= H^.Next;
Read(F, C);
case strtoint(C) of
0:
H^.Data:= '';
1:
H^.Data:= '';
2:
H^.Data:= '';
end;
Read(F, C, C);
S:= '';
while C <> ' ' do
begin
S:= S + C;
Read(F, C);
end;
H^.Name:= S;
S:= '';
Read(F, C);
while C <> ' ' do
begin
S:= S + C;
Read(F, C);
end;
H^.Author:= S;
S:= '';
Read(F, C);
while C <> ' ' do
begin
S:= S + C;
Read(F, C);
end;
H^.Price:= strtoint(S);
S:= '';
Read(F, C);
while not((Ord(C) = 13) or (Ord(C) = 26)) do
begin
S:= S + C;
Read(F, C);
end;
H^.Note:= S;
H^.Next:= nil;
//
Sg.RowCount:= Sg.RowCount + 1;
i:= i + 1;
Sg.Cells[0, i]:= H^.Data;
Sg.Cells[1, i]:= H^.Name;
Sg.Cells[2, i]:= H^.Author;
Sg.Cells[3, i]:= inttostr(H^.Price);
Sg.Cells[4, i]:= H^.Note;
end;
end;
//
CloseFile(F);
end;
end;
//
procedure TFrmMain.RgClick(Sender: TObject);
begin
IsAdded:= false;
if Rg.ItemIndex = 0 then
//
Sort(0);
if Rg.ItemIndex = 1 then
//
Sort(1);
end;
end.
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids;
type
TFrmNewDisk = class(TForm)
EdtName: TEdit;
CmbDiskType: TComboBox;
EdtAuthor: TEdit;
EdtPrice: TEdit;
EdtNote: TEdit;
BtnAddNewDisk: TButton;
BtnChangeDisk: TButton;
LblData: TLabel;
LblName: TLabel;
LblAuthor: TLabel;
LblPrice: TLabel;
LblNote: TLabel;
procedure BtnAddNewDiskClick(Sender: TObject);
procedure BtnChangeDiskClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmNewDisk: TFrmNewDisk;
implementation
{$R *.dfm}
uses unit1;
{ , ,
}
function CheckDisk(H: PDisk): boolean;
var
s: string;
begin
Result:= false;
with FrmNewDisk do
//
while H <> nil do
begin
case CmbDiskType.ItemIndex of
0:
s:= '';
1:
s:= '';
2:
s:= '';
end;
{ , ,
,
, }
if (H^.Data = s) and (H^.Name = EdtName.Text) and
(H^.Author = EdtAuthor.Text) and (inttostr(H^.Price) = EdtPrice.Text)
and (H^.Note = EdtNote.Text) then
begin
Result:= true;
Exit;
end
else
//
H:= H^.Next;
end;
end;
//
procedure AddDisk(H: PDisk);
var
i, j: integer;
Temp: PDisk;
begin
{ , ,
, }
if CheckDisk(Head) = true then
begin
ShowMessage(' .');
Exit;
end
else
//
with FrmNewDisk do
//
if H = nil then
begin
//
New(Head);
with Head^ do
begin
case CmbDiskType.ItemIndex of
0:
Data:= '';
1:
Data:= '';
2:
Data:= '';
end;
Name:= EdtName.Text;
Author:= EdtAuthor.Text;
Price:= strtoint(EdtPrice.Text);
Note:= EdtNote.Text;
Next:= nil;
with FrmMain do
begin
// , 1 ()
Sg.RowCount:= Sg.RowCount + 1;
Sg.Cells[0, Sg.RowCount - 1]:= Head^.Data;
Sg.Cells[1, Sg.RowCount - 1]:= Head^.Name;
Sg.Cells[2, Sg.RowCount - 1]:= Head^.Author;
Sg.Cells[3, Sg.RowCount - 1]:= inttostr(Head^.Price);
Sg.Cells[4, Sg.RowCount - 1]:= Head^.Note;
ShowMessage('CD/DVD .');
end;
end;
end
else
begin
// , ()
if CmbDiskType.ItemIndex = 0 then
begin
New(H);
H^.Data:= '';
H^.Name:= EdtName.Text;
H^.Author:= EdtAuthor.Text;
H^.Price:= strtoint(EdtPrice.Text);
H^.Note:= EdtNote.Text;
H^.Next:= Head;
Head:= H;
with FrmMain do
begin
{ ,
}
if Rg.ItemIndex = 0 then
begin
Sort(0);
ShowMessage('CD/DVD .');
Exit;
end;
{ ,
}
if Rg.ItemIndex = 1 then
begin
Sort(1);
ShowMessage('CD/DVD .');
Exit;
end;
{ ,
() }
Sg.RowCount:= Sg.RowCount + 1;
For i:= Sg.RowCount - 2 downto 1 do
Sg.Rows[i + 1]:= Sg.Rows[i];
Sg.Cells[0, 1]:= Head^.Data;
Sg.Cells[1, 1]:= Head^.Name;
Sg.Cells[2, 1]:= Head^.Author;
Sg.Cells[3, 1]:= inttostr(Head.Price);
Sg.Cells[4, 1]:= Head^.Note;
ShowMessage('CD/DVD .');
Exit;
end;
end;
//
if CmbDiskType.ItemIndex = 1 then
begin
// j - , ()
j:= 1;
// ()
if Head^.Data = '' then
begin
// ()
while H^.Next <> nil do
begin
{ ,
, 1 }
if H^.Next^.Data = '' then
begin
H:= H^.Next;
j:= j + 1;
end
else
{ ,
1 }
begin
j:= j + 1;
break;
end;
end;
// () , 1
if H^.Next = nil then
j:= j + 1;
// ()
Temp:= H^.Next;
New(H^.Next);
with H^.Next^ do
begin
Data:= '';
Name:= EdtName.Text;
Author:= EdtAuthor.Text;
Price:= strtoint(EdtPrice.Text);
Note:= EdtNote.Text;
Next:= Temp;
end;
end
else
// ()
begin
// ()
New(H);
H^.Data:= '';
H^.Name:= EdtName.Text;
H^.Author:= EdtAuthor.Text;
H^.Price:= strtoint(EdtPrice.Text);
H^.Note:= EdtNote.Text;
H^.Next:= Head;
Head:= H;
end;
with FrmMain do
begin
{ ,
}
if Rg.ItemIndex = 0 then
begin
Sort(0);
ShowMessage('CD/DVD .');
Exit;
end;
{ ,
}
if Rg.ItemIndex = 1 then
begin
Sort(1);
ShowMessage('CD/DVD .');
Exit;
end;
{ ,
() }
Sg.RowCount:= Sg.RowCount + 1;
For i:= Sg.RowCount - 2 downto j do
Sg.Rows[i + 1]:= Sg.Rows[i];
Sg.Cells[0, j]:= '';
Sg.Cells[1, j]:= EdtName.Text;
Sg.Cells[2, j]:= EdtAuthor.Text;
Sg.Cells[3, j]:= EdtPrice.Text;
Sg.Cells[4, j]:= EdtNote.Text;
ShowMessage('CD/DVD .');
Exit;
end;
end;
//
if CmbDiskType.ItemIndex = 2 then
begin
// j - , ()
j:= 1;
// ()
if Head^.Data <> '' then
begin
// ()
while H^.Next <> nil do
begin
{ ,
, 1 }
if H^.Next^.Data <> '' then
begin
H:= H^.Next;
j:= j + 1;
end
else
{ ,
1 }
begin
j:= j + 1;
break;
end;
end;
// () , 1
if H^.Next = nil then
j:= j + 1;
// ()
Temp:= H^.Next;
New(H^.Next);
with H^.Next^ do
begin
Data:= '';
Name:= EdtName.Text;
Author:= EdtAuthor.Text;
Price:= strtoint(EdtPrice.Text);
Note:= EdtNote.Text;
Next:= Temp;
end;
end
else
// ()
begin
New(H);
H^.Data:= '';
H^.Name:= EdtName.Text;
H^.Author:= EdtAuthor.Text;
H^.Price:= strtoint(EdtPrice.Text);
H^.Note:= EdtNote.Text;
H^.Next:= Head;
Head:= H;
end;
with FrmMain do
begin
{ ,
}
if Rg.ItemIndex = 0 then
begin
Sort(0);
ShowMessage('CD/DVD .');
Exit;
end;
{ ,