Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Soderzhanie.docx
Скачиваний:
6
Добавлен:
01.07.2025
Размер:
1 Мб
Скачать
☆

3 Разработка технической документации

3.1 Программный код с комментариями

Модуль основного интерфейса программы представляет собой работу основных функциональных элементов программы. Этот модуль является основой программы, исходный код, который представлен ниже.

unit usprint;

interface

uses

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

Dialogs, Grids, StdCtrls, Printers, ComCtrls, DBGrids, Clipbrd,

OleServer, EXCEL97, EXCEL2000, ComObj, ActiveX, ExtCtrls, ExcelXP;

type

TForm1 = class(TForm)

StringGrid1: TStringGrid;

SaveDialog1: TSaveDialog;

XLApp: TExcelApplication;

Panel1: TPanel;

Label1: TLabel;

Button3: TButton;

ComboBox1: TComboBox;

Button8: TButton;

ComboBox2: TComboBox;

Button4: TButton;

Button12: TButton;

Label2: TLabel;

procedure FormCreate(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button8Click(Sender: TObject);

procedure ComboBox1Change(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure Button12Click(Sender: TObject);

procedure StringGrid1Click(Sender: TObject);

procedure StringGrid1DblClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses adsbaz;

{$R *.dfm}

type

TNote=record

kod: string[200];

prod: string[255];

kol: string[150];

st: string[150];

data: string[100];

post: string[200];

adr: string[200];

post1: string[200];

adr1: string[150];

end;

var

NoteFile: file of TNote;

NoteData: TNote;

_Pos: integer;

function GetProgramPath : String;

begin

GetProgramPath:=ExtractFilePath(ParamStr(0));

end;

procedure ShowRecord;

begin

Form3.Edit1.Text:=NoteData.kod;

Form3.RichEdit1.Text:=NoteData.prod;

Form3.Edit2.Text:=NoteData.kol;

Form3.Edit3.Text:=NoteData.st;

Form3.Edit6.Text:=NoteData.data;

Form3.ComboBox2.Text:=Notedata.post;

Form3.ComboBox3.Text:=Notedata.adr;

Form3.ComboBox1.Text:=Notedata.post1;

Form3.ComboBox4.Text:=Notedata.adr1;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

AssignFile(NoteFile,GetProgramPath+'data\'+'adsbaz.dat'); // связываем переменную с файлом

Reset(NoteFile); // открытие файла

_Pos:=0;

if not Eof(NoteFile) then // если в файле есть данные

begin

Read(NoteFile,NoteData); // чтение данных

_Pos:=FilePos(NoteFile)-1; // определение располож. указателя

ShowRecord; // показать данные

end;

StringGrid1.ColWidths[0]:=10;

StringGrid1.ColWidths[1]:=50;

StringGrid1.ColWidths[2]:=100;

StringGrid1.ColWidths[3]:=100;

StringGrid1.ColWidths[4]:=98;

StringGrid1.ColWidths[5]:=100;

StringGrid1.ColWidths[6]:=95;

StringGrid1.ColWidths[7]:=95;

StringGrid1.ColWidths[8]:=100;

StringGrid1.ColWidths[9]:=100;

StringGrid1.ColWidths[10]:=100;

StringGrid1.RowHeights[0]:=20;

StringGrid1.RowCount:=2;

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

StringGrid1.Cells[2,0]:='Код продукции';

StringGrid1.Cells[3,0]:='Наименование продукции';

StringGrid1.Cells[4,0]:='Количество';

StringGrid1.Cells[5,0]:='Стоимость';

StringGrid1.Cells[6,0]:='Äàòà';

StringGrid1.Cells[7,0]:='Поставщик';

StringGrid1.Cells[8,0]:='Адрес';

StringGrid1.Cells[9,0]:='Отдел';

StringGrid1.Cells[10,0]:='Администратор';

Form1.Caption:='Выборка... (0 записей из '+IntToStr(FileSize(NoteFile))+')';

end;

procedure TForm1.Button3Click(Sender: TObject);

Label Thenext1;

Label Thenext2;

Label Thenext3;

var

pPos,i,ch,zap: integer;

s: string;

begin

ch:=0;

for i:=1 to StringGrid1.RowCount-1 do

StringGrid1.Rows[i].Clear;

StringGrid1.RowCount:=2;

StringGrid1.FixedCols:=1;

StringGrid1.FixedRows:=1;

////////////////////////////////////////////////////////////////

if ComboBox1.Text='Äàòà'

then

begin

zap:=0;

for pPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,pPos);

Read(NoteFile,NoteData); // чтение данных

if NoteData.data=''

then goto Thenext2;

s:=NoteData.data;

if pos(ComboBox2.Text,s)<>0

then

begin

ch:=ch+1;

StringGrid1.Cells[1,ch]:=IntToStr(ch)+'.';

StringGrid1.Cells[2,ch]:=NoteData.kod;

StringGrid1.Cells[3,ch]:=NoteData.prod;

StringGrid1.Cells[4,ch]:=NoteData.kol;

StringGrid1.Cells[5,ch]:=NoteData.st;

StringGrid1.Cells[6,ch]:=NoteData.data;

StringGrid1.Cells[7,ch]:=NoteData.post;

StringGrid1.Cells[8,ch]:=NoteData.adr;

StringGrid1.Cells[9,ch]:=NoteData.post1;

StringGrid1.Cells[10,ch]:=NoteData.adr1;

StringGrid1.RowCount:=StringGrid1.RowCount+1;

zap:=zap+1;

Form1.Caption:='Выборка ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

Application.ProcessMessages;

end;

Thenext2:

end;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

StringGrid1.RowCount:=StringGrid1.RowCount-1;

end;

////////////////////////////////////////////////////////////////

if ComboBox1.Text='Поставщик'

then

begin

zap:=0;

for pPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,pPos);

Read(NoteFile,NoteData); // чтение данных

if NoteData.post='' then goto Thenext1;

s:=NoteData.post;

if s=ComboBox2.Text then

begin

ch:=ch+1;

StringGrid1.Cells[1,ch]:=IntToStr(ch)+'.';

StringGrid1.Cells[2,ch]:=NoteData.kod;

StringGrid1.Cells[3,ch]:=NoteData.prod;

StringGrid1.Cells[4,ch]:=NoteData.kol;

StringGrid1.Cells[5,ch]:=NoteData.st;

StringGrid1.Cells[6,ch]:=NoteData.data;

StringGrid1.Cells[7,ch]:=NoteData.post;

StringGrid1.Cells[8,ch]:=NoteData.adr;

StringGrid1.Cells[9,ch]:=NoteData.post1;

StringGrid1.Cells[10,ch]:=NoteData.adr1;

StringGrid1.RowCount:=StringGrid1.RowCount+1;

zap:=zap+1;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

Application.ProcessMessages;

end;

Thenext1:

end;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

StringGrid1.RowCount:=StringGrid1.RowCount-1;

end;

////////////////////////////////////////

if ComboBox1.Text='Наименование продукции'

then

begin

zap:=0;

for pPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,pPos);

Read(NoteFile,NoteData); // чтение данных

if NoteData.prod='' then goto Thenext3;

s:=NoteData.prod;

if s=ComboBox2.Text then

begin

ch:=ch+1;

StringGrid1.Cells[1,ch]:=IntToStr(ch)+'.';

StringGrid1.Cells[2,ch]:=NoteData.kod;

StringGrid1.Cells[3,ch]:=NoteData.prod;

StringGrid1.Cells[4,ch]:=NoteData.kol;

StringGrid1.Cells[5,ch]:=NoteData.st;

StringGrid1.Cells[6,ch]:=NoteData.data;

StringGrid1.Cells[7,ch]:=NoteData.post;

StringGrid1.Cells[8,ch]:=NoteData.adr;

StringGrid1.Cells[9,ch]:=NoteData.post1;

StringGrid1.Cells[10,ch]:=NoteData.adr1;

StringGrid1.RowCount:=StringGrid1.RowCount+1;

zap:=zap+1;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

Application.ProcessMessages;

end;

Thenext3:

end;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

StringGrid1.RowCount:=StringGrid1.RowCount-1;

end;

////////////////////////////////////////////////////////////////

if ComboBox1.Text='Âñå'

then

begin

zap:=0;

for pPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,pPos);

Read(NoteFile,NoteData); //чтение данных

StringGrid1.Cells[1,pPos+1]:=IntToStr(pPos+1)+'.';

StringGrid1.Cells[2,pPos+1]:=NoteData.kod;

StringGrid1.Cells[3,pPos+1]:=NoteData.prod;

StringGrid1.Cells[4,pPos+1]:=NoteData.kol;

StringGrid1.Cells[5,pPos+1]:=NoteData.st;

StringGrid1.Cells[6,pPos+1]:=NoteData.data;

StringGrid1.Cells[7,pPos+1]:=NoteData.post;

StringGrid1.Cells[8,pPos+1]:=NoteData.adr;

StringGrid1.Cells[9,pPos+1]:=NoteData.post1;

StringGrid1.Cells[10,pPos+1]:=NoteData.adr1;

StringGrid1.RowCount:=StringGrid1.RowCount+1;

zap:=zap+1;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

Application.ProcessMessages;

end;

Form1.Caption:='Выборка... ('+IntToStr(zap)+' записей из '+IntToStr(FileSize(NoteFile))+')';

StringGrid1.RowCount:=StringGrid1.RowCount-1;

end;

////////////////////////////////////////////////////////////////

//Button1.Enabled:=true;

//Button2.Enabled:=true;

// Button6.Enabled:=true;

//Button6.Enabled:=true;

Button8.Enabled:=true;

//Button9.Enabled:=true;

Button12.Enabled:=true;

end;

procedure AutoSizeGridColumn(Grid: TStringGrid; column: integer);

var

i: integer;

temp: integer;

max: integer;

begin

max:=0;

for i:=0 to Grid.RowCount-1 do

begin

temp:=Grid.Canvas.TextWidth(Grid.Cells[column, i]);

if temp>max

then max:=temp;

end;

Grid.ColWidths[column]:=Max+Grid.GridLineWidth+6;

end;

procedure TForm1.Button8Click(Sender: TObject);

var

i: integer;

begin

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

AutoSizeGridColumn(StringGrid1, i);

end;

procedure TForm1.ComboBox1Change(Sender: TObject);

var

cPos, i, j: integer;

s: string;

begin

if ComboBox1.Text='Âñå'

then ComboBox2.Enabled:=false

else ComboBox2.Enabled:=true;

//////////// поставщик

if ComboBox1.Text='Поставщик' then

begin

ComboBox2.Text:='';

ComboBox2.Items.Clear;

cPos:=0;

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.post;

for i:=0 to FileSize(NoteFile)-1 do

begin

if s<>'' then

begin

ComboBox2.Text:=s;

ComboBox2.Items.Add(s);

break;

end;

inc(cPos);

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.post;

end;

for cPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.post;

if s<>'' then

begin

for i:=0 to ComboBox2.Items.Count-1 do

if pos(s,ComboBox2.Items.Strings[i])=0

then j:=2

else

begin

j:=1;

Break;

end;

end;

if j=2 then ComboBox2.Items.Add(s);

j:=0;

end;

end;

//////////// Наименование

if ComboBox1.Text='Наименование продукции' then

begin

ComboBox2.Text:='';

ComboBox2.Items.Clear;

cPos:=0;

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.prod;

for i:=0 to FileSize(NoteFile)-1 do

begin

if s<>'' then

begin

ComboBox2.Text:=s;

ComboBox2.Items.Add(s);

break;

end;

inc(cPos);

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.prod;

end;

for cPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.prod;

if s<>'' then

begin

for i:=0 to ComboBox2.Items.Count-1 do

if pos(s,ComboBox2.Items.Strings[i])=0

then j:=2

else

begin

j:=1;

Break;

end;

end;

if j=2 then ComboBox2.Items.Add(s);

j:=0;

end;

end;

//////////////Äàòà

if ComboBox1.Text='Äàòà' then

begin

ComboBox2.Text:='';

ComboBox2.Items.Clear;

cPos:=0;

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.data;

for i:=0 to FileSize(NoteFile)-1 do

begin

if s<>'' then

begin

ComboBox2.Text:=s;

ComboBox2.Items.Add(s);

break;

end;

inc(cPos);

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.data;

end;

for cPos:=0 to FileSize(NoteFile)-1 do

begin

Seek(NoteFile,cPos);

Read(NoteFile,NoteData); // чтение данных

s:=NoteData.data;

if s<>'' then

begin

for i:=0 to ComboBox2.Items.Count-1 do

if pos(s,ComboBox2.Items.Strings[i])=0

then j:=2

else

begin

j:=1;

Break;

end;

end;

if j=2 then ComboBox2.Items.Add(s);

j:=0;

end;

////////////////////////////////////////////////////////////////

ComboBox2.Sorted:=true;

end;

end;

procedure TForm1.Button12Click(Sender: TObject);

var

i,j,r,c: integer;

Excel,WorkBook,Sheet,TabGrid: Variant;

iIndex: OleVariant;

s: string;

f: textfile;

begin

AssignFile(f,ExtractFilePath(Application.ExeName)+'\data\firm_name.txt');

if FileExists(ExtractFilePath(Application.ExeName)+'\data\firm_name.txt')

then

begin

Reset(f);

Read(f,s);

end

else

begin

s:='Наименование организации';

Rewrite(f);

Write(f,s);

end;

CloseFile(f);

//

s:=InputBox('Наименование вашей организации','Введите наименование:',s);

if s='' then

begin

MessageDlg('Для передачи данных в Excel требуется ввести название вашей организации!',mtInformation,[mbOK],0);

Exit;

end;

//

AssignFile(f,ExtractFilePath(Application.ExeName)+'\data\firm_name.txt');

Rewrite(f);

Write(f,s);

CloseFile(f);

// 'Наименование Вашей организации:'

//

iIndex:=1;

r:=StringGrid1.RowCount; // кол-во строк

c:=StringGrid1.ColCount; // кол-во столбцов

// Созда¸м массив-матрицу

TabGrid:=VarArrayCreate([0,(r-1),0,(c-1)],VarOleStr);

i:=0;

// Определяем цикл для заполнения массива-матрицы

repeat

for j:=0 to (c-1) do // заполнение TabGrid из StringGrid1

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

inc(i,1);

until i>(r-1);

// Загружаем Excel

try

Excel:=CreateOleObject('Excel.Application'); // для остальных

except

Excel:=CreateOleObject('Excel.Application.10'); // äëÿ Office XP

end;

Excel.SheetsInNewWorkbook:=1;

WorkBook:=Excel.WorkBooks.Add;

Sheet:=WorkBook.WorkSheets[1];

Sheet.Name:='Кладовщик - Отчет';

Sheet.Range['A6',Sheet.Cells.Item[r+5,c-1]].Value:=TabGrid;

// Ориентация страницы: книжная (xlPortrait или :=1)

Sheet.PageSetup.CenterHorizontally:=true;

Sheet.PageSetup.Orientation:=xlLandscape; // альбомная (или :=2)

// Поля (дробные числа разделяются только '.')

Sheet.PageSetup.LeftMargin:=Excel.CentimetersToPoints(1);

Sheet.PageSetup.RightMargin:=Excel.CentimetersToPoints(1);

Sheet.PageSetup.TopMargin:=Excel.CentimetersToPoints(1);

Sheet.PageSetup.BottomMargin:=Excel.CentimetersToPoints(1);

// Колонтитулы (дробные числа разделяются только '.')

Sheet.PageSetup.HeaderMargin:=Excel.CentimetersToPoints(0.5);

// &С, &К, &Д - страница, колво (всего), дата (dd,mm,yy)

// только для русского MS-Office; для English - &P, &N, &D

Sheet.PageSetup.RightHeader:='Страница &С из &К - &Д';

// Свойства таблицы

Sheet.Columns.WrapText:=true; // переносить по словам

Sheet.Cells.Columns.AutoFit; // автовысота строк

Sheet.Range['A'+IntToStr(6),'J'+IntToStr(6)].RowHeight:=28;

Sheet.Columns.HorizontalAlignment:=xlLeft;

Sheet.Columns.VerticalAlignment:=xlCenter;

Sheet.Columns.ColumnWidth:=12;

Sheet.Columns.Font.Size:=8;

// Шапка над таблицей ([3,4] - строка, столбец)

Sheet.Cells[3,4]:=s+' - Отчет за '+DateToStr(Date);

Sheet.Range['A3','J3'].HorizontalAlignment:=xlHAlignCenter;

Sheet.Range['A3','J3'].Font.Name:='Times New Roman';

Sheet.Range['A3','J3'].Font.Bold:=true;

Sheet.Range['A3','J3'].Font.Size:=14;

Sheet.Range['A3','J3'].Columns.WrapText:=false;

// Обрамление ячеек (xlDouble,...)

Sheet.Range['A'+IntToStr(6),'J'+IntToStr(r+5)].Columns.Borders.LineStyle:=xlContinuous;

// Ширина столбцов

Sheet.Range['A'+IntToStr(6),'A'+IntToStr(r+5)].ColumnWidth:=6;

Sheet.Range['B'+IntToStr(6),'B'+IntToStr(r+5)].ColumnWidth:=24;

Sheet.Range['C'+IntToStr(6),'C'+IntToStr(r+5)].ColumnWidth:=22;

Sheet.Range['D'+IntToStr(6),'D'+IntToStr(r+5)].ColumnWidth:=14;

Sheet.Range['E'+IntToStr(6),'E'+IntToStr(r+5)].ColumnWidth:=12;

Sheet.Range['F'+IntToStr(6),'F'+IntToStr(r+5)].ColumnWidth:=12;

Sheet.Range['G'+IntToStr(6),'G'+IntToStr(r+5)].ColumnWidth:=8;

Sheet.Range['H'+IntToStr(6),'H'+IntToStr(r+5)].ColumnWidth:=12;

Sheet.Range['I'+IntToStr(6),'I'+IntToStr(r+5)].ColumnWidth:=12;

Sheet.Range['J'+IntToStr(6),'J'+IntToStr(r+5)].ColumnWidth:=12;

// Размер шрифта 6-го столбца

Sheet.Range['A'+IntToStr(6),'J'+IntToStr(6)].Font.Size:=10;

// Выравнивание первого столбца

Sheet.Range['A'+IntToStr(6),'A'+IntToStr(r+5)].HorizontalAlignment:=xlHAlignCenter;

Sheet.Range['A'+IntToStr(6),'A'+IntToStr(r+5)].Font.Bold:=true;

// Выравнивание первой строки

Sheet.Range['A'+IntToStr(6),'J'+IntToStr(6)].HorizontalAlignment:=xlCenter;

Sheet.Range['A'+IntToStr(6),'J'+IntToStr(6)].Font.Bold:=true;

// Показываем Excel

Excel.Visible:=True;

Excel.ScreenUpdating:=true;

// Unassign the Delphi Variant Matrix

Excel:=Unassigned;

WorkBook:=Unassigned;

Sheet:=Unassigned;

TabGrid:=Unassigned;

end;

procedure TForm1.Button4Click(Sender: TObject);

begin

Close;

end;

procedure TForm1.StringGrid1Click(Sender: TObject);

begin

StringGrid1.ShowHint:=false;

end;

procedure TForm1.StringGrid1DblClick(Sender: TObject);

var

i,j:integer;

begin

StringGrid1.ShowHint:=true;

j:=StringGrid1.Row;

StringGrid1.Hint:=StringGrid1.Cells[1,j];

for i:=2 to StringGrid1.ColCount-1 do

StringGrid1.Hint:=StringGrid1.Hint+' - '+StringGrid1.Cells[i,j];

end;

end.

С листингом остальных модулей можно ознакомиться в приложении на диске с программой.

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