Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
###ПЗ_ЯН_ЧАОnew.doc
Скачиваний:
9
Добавлен:
31.08.2019
Размер:
2.7 Mб
Скачать

Приложение а

Текст модуля “Головной склад”

unit Unit11;

interface

uses

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

Dialogs, Grids, StdCtrls, Buttons;

type

TForm11 = class(TForm)

StringGrid1: TStringGrid;

Memo1: TMemo;

Memo2: TMemo;

StringGrid2: TStringGrid;

RadioButton1: TRadioButton;

RadioButton2: TRadioButton;

RadioButton3: TRadioButton;

Edit1: TEdit;

Edit2: TEdit;

Edit3: TEdit;

Label1: TLabel;

StaticText1: TStaticText;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

Memo3: TMemo;

procedure FormActivate(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form11: TForm11;

implementation

{$R *.dfm}

procedure TForm11.FormActivate(Sender: TObject);

label h;

var f: TextFile; // файл

fName: string[80]; // имя файла

buf: string[80]; // буфер для чтения строк

n, i, p, j: integer;

a: array [1..50] of string;

str: string;

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]:='Кол-во в магазине';

Form11.Height:=284;

Memo1.Clear;

AssignFile(f, 'Приход товара.txt');

try

Reset(f); // открыть для чтения

except on EInOutError do begin

ShowMessage('Ошибка доступа к файлу '+ 'Приход товара.txt');

exit;

end;

end;

// чтение из файла

while not EOF(f) do begin

readln(f, buf); // прочитать строку из файла

Memo1.Lines.Add(buf); // добавить строку в поле Memo1

end;

CloseFile(f); // закрыть файл

Memo2.Clear;

n:=Memo1.Lines.Count;

for i:=0 to n-1 do begin

a[i]:=Memo1.Lines[i];

if a[i]='' then continue else Memo2.Lines.Add(a[i]);

end;

n:=Memo1.Lines.Count;

for i:=0 to n do begin

a[i]:=Memo1.Lines[i];

for j:=1 to 4 do begin

p:=pos('*',a[i]);

StringGrid1.Cells[j-1,i+1]:=copy(a[i],1,(p-1));

delete(a[i],1,p);

end;

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

end;

Memo3.Clear;

AssignFile(f, 'Весь товар.txt');

try

Reset(f); // открыть для чтения

except on EInOutError do begin

ShowMessage('Ошибка доступа к файлу '+ 'Весь товар.txt');

exit;

end;

end;

while not EOF(f) do begin

readln(f, buf); // прочитать строку из файла

Memo3.Lines.Add(buf); // добавить строку в поле Memo1

end;

CloseFile(f); // закрыть файл

n:=Memo3.Lines.Count;

for i:=0 to n-1 do begin

a[i]:=Memo3.Lines[i];

if a[i]='' then goto h;

p:=pos('*',a[i]);

str:=copy(a[i],1,(p-1));

for j:=1 to StringGrid1.RowCount do begin

if str=StringGrid1.Cells[0,j] then begin

p:=pos('*',a[i]);

delete(a[i],1,p);

p:=pos('*',a[i]);

delete(a[i],1,p);

p:=pos('*',a[i]);

delete(a[i],1,p);

p:=pos('*',a[i]);

delete(a[i],1,p);

StringGrid1.Cells[5,j]:=a[i];

end;

end;

h: end;

end;