Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
otchet_po_programirovaniyu (2).doc
Скачиваний:
6
Добавлен:
12.04.2015
Размер:
2.04 Mб
Скачать

Заключение

В ходе выполнения курсовой работы выполнено следующее:

Изучены средства IDEDelphi, позволяющие организовать работу с текстовыми файлами, а также приемы создания простейших многооконных приложений.

С помощью IDE Delphi разработано программное средство, позволяющее организовать ввод, просмотр и редактирование данных, хранящихся в текстовом файле. Предметная область: страны мира. Структура записи: название, столица, площадь, население, государственный строй, континент.

Также программа позволяет выполнять следующие действия:

  1. Сохранить сформированный список стран в файл;

  2. Загрузить ранее сохраненный список из файла;

  3. Поиск информации – последовательно находить несколько записей, удовлетворяющих заданному значению поля «Государственному строю»;

  4. Фильтрацию данных – формирование списка сотрудников, которые имеют заданное значение в поле «Континенту»;

  5. Сортировку списка сотрудников по полю «Площадь» по возрастанию.

Листинг

unit Unit1;

interface

uses

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

Dialogs, StdCtrls, Buttons, Mask, Menus, Grids, ExtCtrls;

type

TForm1 = class(TForm)

Panel1: TPanel;

Panel2: TPanel;

GroupBox1: TGroupBox;

GroupBox2: TGroupBox;

StringGrid1: TStringGrid;

Label1: TLabel;

Edit1: TEdit;

Label2: TLabel;

Label3: TLabel;

ComboBox1: TComboBox;

Label4: TLabel;

Edit2: TEdit;

Label5: TLabel;

ComboBox2: TComboBox;

BitBtn1: TBitBtn;

RadioButton1: TRadioButton;

RadioButton2: TRadioButton;

RadioButton3: TRadioButton;

RadioButton4: TRadioButton;

Label6: TLabel;

ComboBox3: TComboBox;

Label7: TLabel;

BitBtn2: TBitBtn;

dlgOpen1: TOpenDialog;

SaveDialog: TSaveDialog;

mm1: TMainMenu;

N1: TMenuItem;

N2: TMenuItem;

N3: TMenuItem;

N4: TMenuItem;

N5: TMenuItem;

N6: TMenuItem;

N7: TMenuItem;

N8: TMenuItem;

Edit4: TEdit;

Label8: TLabel;

Edit5: TEdit;

ComboBox4: TComboBox;

N9: TMenuItem;

N10: TMenuItem;

N11: TMenuItem;

Spravini1: TMenuItem;

//procedure ComboBox1Change(Sender: TObject);

//procedure Panel2Click(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

procedure N3Click(Sender: TObject);

//procedure N6Click(Sender: TObject);

//procedure BitBtn2Click(Sender: TObject);

procedure ShowList;

procedure FormCreate(Sender: TObject);

procedure N2Click(Sender: TObject);

procedure N5Click(Sender: TObject);

procedure N8Click(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);

procedure N7Click(Sender: TObject);

procedure N10Click(Sender: TObject);

procedure N12Click(Sender: TObject);

procedure Spravini1Click(Sender: TObject);

//procedure ComboBox1Change(Sender: TObject);

//procedure N5Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

n,ip:Integer;

s:string;

implementation

uses Unit2, Unit3, Unit4,Unit5, Unit6;

{$R *.dfm}

procedure TForm1.ShowList;

var

t:TextFile;

d:string;

begin

n:=1;

Reset(t,s);

while not Eof(t) do

begin

n:=n+1;

StringGrid1.RowCount:=n;

StringGrid1.Cells[0,n-1]:=IntToStr(n-1);

Readln(t,d);StringGrid1.Cells[1,n-1]:=d;

Readln(t,d);StringGrid1.Cells[2,n-1]:=d;

Readln(t,d);StringGrid1.Cells[3,n-1]:=d;

Readln(t,d);StringGrid1.Cells[4,n-1]:=d;

Readln(t,d);StringGrid1.Cells[5,n-1]:=d;

Readln(t,d);StringGrid1.Cells[6,n-1]:=d;

end;

CloseFile(t);

n:=n+1;

StringGrid1.RowCount:=n;

StringGrid1.FixedRows:=1;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);

begin

StringGrid1.Cells[0,n-1]:=IntToStr(n-1);

StringGrid1.Cells[1,n-1]:=Edit1.Text;

StringGrid1.Cells[2,n-1]:=Edit4.Text;

StringGrid1.Cells[3,n-1]:=ComboBox1.Text;

StringGrid1.Cells[4,n-1]:=Edit2.Text;

StringGrid1.Cells[5,n-1]:=Edit5.Text;

StringGrid1.Cells[6,n-1]:=ComboBox2.Text;

n:=n+1;

StringGrid1.RowCount:=n;

end;

procedure TForm1.N3Click(Sender:TObject);

begin

if dlgOpen1.Execute then

begin

s:=dlgOpen1.FileName;

ShowList;

end;

end;

procedure TForm1.FormCreate(Sender: TObject);

var

t:TextFile;

d:string;

begin

AssignFile(t,'Sprav.ini');

Reset(t);

while not Eof(t) do

begin

Readln(t,d);

ComboBox2.Items.add(d);

Combobox4.Items.add(d);

end;

ComboBox2.ItemIndex:=0;

ComboBox4.ItemIndex:=0;

CloseFile(t);

n:=2; 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]:='Гос.строй';

ip:=0;

s:=' ';

end;

procedure TForm1.N2Click(Sender: TObject);

var

t:TextFile;

i:Integer;

begin

if SaveDialog.Execute then

begin

s:=SaveDialog.FileName;

Rewrite(t,s);

for i:=1 to n-2 do

begin

Writeln(t,StringGrid1.Cells[1,i]);

Writeln(t,StringGrid1.Cells[2,i]);

Writeln(t,StringGrid1.Cells[3,i]);

Writeln(t,StringGrid1.Cells[4,i]);

Writeln(t,StringGrid1.Cells[5,i]);

Writeln(t,StringGrid1.Cells[6,i]);

end;

CloseFile(t);

end;

end;

procedure TForm1.N5Click(Sender: TObject);

begin

Application.Terminate;

end;

procedure TForm1.N8Click(Sender: TObject);

begin

form2.ShowModal;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);

procedure Sort;

var i,k:Integer;

s1:string;

begin

for k:=n-2 downto 2 do

for i:=1 to k-1 do

begin

if StrToInt(StringGrid1.Cells[4,i])>StrToInt(StringGrid1.Cells[4,i+1]) then

begin

s1:=StringGrid1.Cells[1,i];

StringGrid1.Cells[1,i]:=StringGrid1.Cells[1,i+1];

StringGrid1.Cells[1,i+1]:=s1;

s1:=StringGrid1.Cells[2,i];

StringGrid1.Cells[2,i]:=StringGrid1.Cells[2,i+1];

StringGrid1.Cells[2,i+1]:=s1;

s1:=StringGrid1.Cells[3,i];

StringGrid1.Cells[3,i]:=StringGrid1.Cells[3,i+1];

StringGrid1.Cells[3,i+1]:=s1;

s1:=StringGrid1.Cells[4,i];

StringGrid1.Cells[4,i]:=StringGrid1.Cells[4,i+1];

StringGrid1.Cells[4,i+1]:=s1;

s1:=StringGrid1.Cells[5,i];

StringGrid1.Cells[5,i]:=StringGrid1.Cells[5,i+1];

StringGrid1.Cells[5,i+1]:=s1;

s1:=StringGrid1.Cells[6,i];

StringGrid1.Cells[6,i]:=StringGrid1.Cells[6,i+1];

StringGrid1.Cells[6,i+1]:=s1;

end;

end;

end;

procedure Filter;

var i,j:Integer;

begin

i:=1;

while i<=n-2 do

if StringGrid1.Cells[3,i]<>ComboBox3.Text then

begin

for j:=i+1 to n do

begin

StringGrid1.Cells[1,J-1]:=StringGrid1.Cells[1,j];

StringGrid1.Cells[2,J-1]:=StringGrid1.Cells[2,j];

StringGrid1.Cells[3,J-1]:=StringGrid1.Cells[3,j];

StringGrid1.Cells[4,J-1]:=StringGrid1.Cells[4,j];

StringGrid1.Cells[5,J-1]:=StringGrid1.Cells[5,j];

StringGrid1.Cells[6,J-1]:=StringGrid1.Cells[6,j];

end;

n:=n-1;

end else i:=i+1;

StringGrid1.RowCount:=n;

StringGrid1.Cells[0,n-1]:=' ';

end;

procedure Poisk;

var i:Integer;

Sel:TGridRect;

begin

i:=ip+1;

while (StringGrid1.Cells[6,i]<>ComboBox4.Text) and (i<n-1) do i:=i+1;

if i>n-2 then

begin

ip:=0;Sel.Right:=1;Sel.Top:=1;Sel.Bottom:=1;

StringGrid1.Selection:=Sel;

ShowMessage('Достигнут конец списка.Государственного устройства не найдено!');

end

else

begin

ip:=i;Sel.Left:=1;Sel.Right:=5;Sel.Top:=ip;Sel.Bottom:=ip;

StringGrid1.Selection:=Sel;

end;

end;

begin

if RadioButton1.Checked

then Sort

else if RadioButton2.Checked

then Filter

else if RadioButton3.Checked

then Poisk

else if RadioButton4.Checked

then if s<>' ' then ShowList

else ShowMessage('Список не связан с файлом!Вывод невозможен!')

else ShowMessage('Укажите действие');

end;

procedure TForm1.N7Click(Sender: TObject);

begin

form3.ShowModal;

end;

procedure TForm1.N10Click(Sender: TObject);

var

i,x,y:Integer;

begin

for y:=StringGrid1.Row+1 to StringGrid1.RowCount-1 do

for x:=0 to StringGrid1.ColCount-1 do

StringGrid1.Cells[x,y-1]:=StringGrid1.Cells[x,y];

StringGrid1.RowCount:=StringGrid1.RowCount-1;

end;

procedure TForm1.N12Click(Sender: TObject);

begin

if StringGrid1.RowCount>1 then

StringGrid1.RowCount:=StringGrid1.RowCount+1;

end;

procedure TForm1.Spravini1Click(Sender: TObject);

var t: textfile;

d:string;

begin

form6.Mmo1.Lines.Clear;

begin

reset(t,'Sprav.ini');

closefile(t);

begin

form6.show

end;

end;

end;

end.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]