📄 item.~pas
字号:
unit item;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BaseInfo, Menus, ActnList, DB, DBClient, Grids, DBGridEh,
StdCtrls, wwdblook, Buttons, ToolWin, ComCtrls, ExtCtrls, FR_DSet,inifiles,
comobj, Excel2000,FR_DBSet, FR_Class, FR_Desgn;
type
Tfrmitem = class(TfrmBaseinfo)
CDSbaseinfofid: TAutoIncField;
CDSbaseinfofsaleprice: TBCDField;
CDSbaseinfofsalehortation: TBCDField;
CDSbaseinfofiffew: TBooleanField;
CDSbaseinfofminstore: TBCDField;
CDSbaseinfoffunitqty: TFloatField;
CDSbaseinfofsort: TStringField;
CDSbaseinfofunit2qty: TFloatField;
CDSbaseinfofunit1qty: TFloatField;
CDSbaseinfocolorno: TStringField;
CDSbaseinfocolor: TStringField;
CDSbaseinfogno: TStringField;
CDSbaseinfozs: TStringField;
CDSbaseinfock: TStringField;
CDSbaseinfoqty: TFloatField;
CDSbaseinfosafeqty: TFloatField;
CDSbaseinfocgyrqty: TFloatField;
CDSbaseinfocgwjqty: TFloatField;
CDSbaseinfofcode: TStringField;
CDSbaseinfofname: TStringField;
CDSbaseinfofunit: TStringField;
CDSbaseinfoftype: TStringField;
CDSbaseinfofnote: TStringField;
CDSbaseinfofunit1: TStringField;
CDSbaseinfofunit2: TStringField;
BitBtn1: TBitBtn;
OpenDialog1: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure comboPrintChange(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmitem: Tfrmitem;
implementation
uses Global, uitem_m;
{$R *.dfm}
procedure Tfrmitem.FormCreate(Sender: TObject);
begin
inherited;
Maintable:='titem';
Mainview:='vitem';
Keyfield:='fid';
ReportName:=gs_appPath+'\prints\fritem.frf';
Modifyform:=Tfrmitem_m;
end;
procedure Tfrmitem.comboPrintChange(Sender: TObject);
var
excelid, mybook: variant;
row, col, i, j, colcount, frow: integer;
excelflg: boolean;
rpstr: string;
per_count, datasum, dsum1, dsum2: integer;
datas1, datas2, datas3: string;
begin
inherited;
if Trim(comboprint.Text)='电子表格' then
begin
CDSbaseinfo.DisableControls;
try
excelid := createoleobject('excel.application');
mybook := createoleobject('excel.sheet');
mybook := excelid.workbooks.add;
row := 1;
col := 1;
excelflg := true;
except
excelflg := false;
application.MessageBox('请确定EXCEL是否正确安装!', '提示信息', mb_ok);
end;
if excelflg then
begin
colcount := CDSbaseinfo.fieldcount;
excelid.range['A' + inttostr(row), chr(64 + colcount) +
inttostr(row)].merge();
mybook.worksheets[1].cells.item[row, col] := '基本报表';
mybook.worksheets[1].cells.item[row, col].font.size := 18;
mybook.worksheets[1].cells.item[row, col].font.bold := true;
mybook.worksheets[1].cells.item[row, col].HorizontalAlignment := xlcenter;
row := row + 1;
excelid.range['A' + inttostr(row), chr(64 + colcount) +
inttostr(row)].merge();
mybook.worksheets[1].cells.item[row, col] := '报表日期:' +
datetostr(date);
row := row + 1;
frow := row;
CDSbaseinfo.First;
for i := 1 to colcount do
begin
excelid.columns[i].ColumnWidth := Grid.Columns[i - 1].Width /
8;
excelid.columns[i].NumberFormatLocal := '@';
mybook.worksheets[1].cells.item[row, i] := grid.Columns[i -
1].Title.Caption;
mybook.worksheets[1].cells.item[row, i].HorizontalAlignment := xlcenter;
end;
row := row + 1;
while not CDSbaseinfo.Eof do
begin
for i := 1 to colcount do
mybook.worksheets[1].cells.item[row, i] := CDSbaseinfo.Fields[i -
1].AsString;
row := row + 1;
CDSbaseinfo.Next;
end;
excelid.range['A' + inttostr(row), chr(64 + colcount) +
inttostr(row)].merge();
mybook.worksheets[1].cells.item[row, col].font.size := 12;
mybook.worksheets[1].cells.item[row, col].font.bold := true;
mybook.worksheets[1].cells.item[row, col].HorizontalAlignment := xlcenter;
mybook.worksheets[1].cells.item[row, col] := '总记录数:' +
inttostr(CDSbaseinfo.RecordCount) + '条';
row := row + 1;
rpstr := '报表条件:';
{ if grid.Cells[0, 0] <> '' then
for i := 0 to grid.RowCount - 1 do
for j := 0 to 3 do
rpstr := rpstr + ' ' + grid.Cells[j, i]; }
excelid.range['A' + inttostr(row), chr(64 + colcount) +
inttostr(row)].merge();
mybook.worksheets[1].cells.item[row, col] := rpstr;
row := row + 1;
excelid.range[chr(65) + inttostr(frow), chr(64 + colcount) + inttostr(row
- 1)].Borders[1].LineStyle := xlContinuous;
excelid.range[chr(65) + inttostr(frow), chr(64 + colcount) + inttostr(row
- 1)].Borders[2].LineStyle := xlContinuous;
excelid.range[chr(65) + inttostr(frow), chr(64 + colcount) + inttostr(row
- 1)].Borders[3].LineStyle := xlContinuous;
excelid.range[chr(65) + inttostr(frow), chr(64 + colcount) + inttostr(row
- 1)].Borders[4].LineStyle := xlContinuous;
// end;
excelid.visible := true;
end;
CDSbaseinfo.EnableControls;
end;
end;
procedure Tfrmitem.BitBtn1Click(Sender: TObject);
var
s,str1,str2,str3,str4,str5:string;
i, ii,jj:integer;
ini:textfile;
Searcht, usercode:string;
begin
inherited;
opendialog1.Execute;
s:=OpenDialog1.FileName;
if not FileExists(s) then //判断此文件是否存在
showmessage('该文件不存在')
else
begin
AssignFile(ini,s);
reset(ini);
// i:=1;
while not eof(ini) do
begin
Readln(ini,usercode);
ii:=length(usercode);
jj:=Pos(',',usercode);
str1:=copy(usercode,1,jj-1);
/////////////////// str1
usercode:= copy(usercode,jj+1,ii-jj);
ii:=length(usercode);
jj:=Pos(',',usercode) ;
str2:=copy(usercode,1,jj-1);
////////////////////// str2
usercode:= copy(usercode,jj+1,ii-jj);
ii:=length(usercode);
jj:=Pos(',',usercode) ;
str3:=copy(usercode,1,jj-1);
/////////////////////////////str3
usercode:= copy(usercode,jj+1,ii-jj);
ii:=length(usercode);
jj:=Pos(',',usercode) ;
str4:=copy(usercode,1,jj-1);
///////////////////////////////////str4
str5:= copy(usercode,jj+1,ii-jj);
// spbtnadd.Click;
CDSbaseinfo.Append;
CDSbaseinfo['fcode']:=str1;
CDSbaseinfo['fname']:=str2;
CDSbaseinfo['ftype']:=str3;
CDSbaseinfo['funit']:=str4;
CDSbaseinfo['zs'] :=str5;
end;
//i:=i+1;
// CdsSub.FieldByName('fcode').AsString:=str1;
// CdsSub.FieldByName('fqty').AsString:=str2;
end;
CloseFile(ini);
// CDSbaseinfo.ApplyUpdates()
CDSbaseinfo.Post;
//CDSbaseinfo.ApplyUpdates(-1)//
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -