📄 cf0ch.~pas
字号:
inherited;
adoquery1.Close;
adoquery1.SQL.clear;
adoquery1.sql.add('select distinct 机型 from '+main.username+' ');
adoquery1.open;
y:=0;
while not adoquery1.Eof do
begin
y:=y+1;
mytable[y,1]:=adoquery1.fieldbyname('机型').asstring;
adoquery2.Close;
adoquery2.SQL.clear;
adoquery2.sql.add('select 电子串号 from '+main.username+' where 机型='''+adoquery1.fieldbyname('机型').AsString+'''');
adoquery2.open;
mytable[y,2]:=inttostr(adoquery2.RecordCount);
adoquery1.Next;
end;
mess:='本次查询如下:'+#13+'';
w:=y;
y:=1;
while y<=w do
begin
mess1:=mess1+#13+'机型名称为:【'+mytable[y,1]+'】,有【'+mytable[y,2]+'】个电子串号';
mess2:=mess2+strtoint(mytable[y,2]);
y:=y+1;
end;
mess:=mess+mess1+''+#13+' 共计【'+inttostr(mess2)+'】个电子串号';
if application.MessageBox(pchar(mess),'注意',mb_yesno)=id_yes then
begin
DlgSave:=TsaveDialog.Create(nil);
DlgSave.FileName:='串号明细.xls';
DlgSave.Filter:='*.xls|*.xls';
if DlgSave.Execute then
Begin
application.ProcessMessages;
Filename:=DlgSave.FileName;
if fileExists(DlgSave.FileName) then
begin
// if application.MessageBox(pchar('系统发现【'+filename+'】文件已经存在,如果继续将删除原文件?'),'提示',mb_yesno)=id_yes then
if messagedlg(pchar('系统发现【'+filename+'】文件已经存在,如果继续将删除原文件?'),mtWarning,[mbyes,mbno],0)=mryes then
begin
DeleteFile(filename);
ExcelApp:= CreateOleObject( 'Excel.Application' );
ExcelApp.Caption :='电脑维护管理系统';//'Microsoft Excel';
ExcelApp.WorkBooks.Add;
application.ProcessMessages;
ExcelApp.WorkSheets[1].Activate;
//首行数据
ExcelApp.rows[1].font.name:='宋体';
ExcelApp.rows[1].font.size:=11;
ExcelApp.rows[1].Font.Color:=clblack;
ExcelApp.rows[1].Font.Bold:=true;
K:=1;
for i:=0 To DBGrid1.Columns.Count-1 Do
begin
if DBGrid1.Columns[i].Visible Then
begin
ExcelApp.Cells[1,K]:=DBGrid1.Columns[i].Title.Caption;
// ExcelApp.rows[2].color:=clred;
k:=k+1;
end;//if
end; //for
//除首行外数据
j:=1;
begin
Gauge_process.Visible:=true;
// stepcount:=DBGrid1.Columns.Count-1;
// with progressBar1 do
// begin
// Min:=0;
// Max:=stepcount;
// Step:=1;
With Gauge_process do
begin
Gauge_process.MaxValue:=DBGrid1.Columns.Count*adoquery3.recordcount;
Gauge_process.Progress:=0;
for x:=0 to DBGrid1.Columns.Count-1 do
begin
if DBGrid1.Columns[x].Visible=true Then
begin
adoquery3.First;
for k:=1 To adoquery3.RecordCount Do
begin
ExcelApp.Cells[K+1,x+1]:=''''+adoquery3.FieldByName(DBGrid1.Columns[x].FieldName).Asstring+'';
// ExcelApp.rows[2].color:=clred;
adoquery3.Next;
Gauge_process.Progress :=Gauge_process.Progress +1;
end;
end;
// showmessage(''+inttostr(x)+'');
// Stepit;
end;
end;
end;
Gauge_process.Visible:=false;
for x:=1 To adoquery3.recordcount+1 Do
ExcelApp.rows[x].Font.SIZE:=10;
ExcelApp.Columns.AutoFit;
ExcelApp.ActiveWorkBook.saveas(filename);
ExcelApp.WorkBooks.Close;
// Application.MessageBox(pchar('数据导出成功,请到【'+filename+'】中查看!'),'数据导出',0);
messagedlg(pchar('数据导出成功,请到【'+filename+'】中查看!'),mtinformation,[mbok],0);
ExcelApp.Quit;
ExcelApp:=Unassigned;
DlgSave.Destroy;
end;
end
else
begin
ExcelApp:= CreateOleObject( 'Excel.Application' );
ExcelApp.Caption :='电脑维护管理系统';//'Microsoft Excel';
ExcelApp.WorkBooks.Add;
application.ProcessMessages;
ExcelApp.WorkSheets[1].Activate;
//首行数据
ExcelApp.rows[1].font.name:='宋体';
ExcelApp.rows[1].font.size:=11;
ExcelApp.rows[1].Font.Color:=clblack;
ExcelApp.rows[1].Font.Bold:=true;
K:=1;
for i:=0 To DBGrid1.Columns.Count-1 Do
begin
if DBGrid1.Columns[i].Visible Then
begin
ExcelApp.Cells[1,K]:=DBGrid1.Columns[i].Title.Caption;
k:=k+1;
end;//if
end; //for
//除首行外数据
j:=1;
begin
Gauge_process.Visible:=true;
// stepcount:=DBGrid1.Columns.Count-1;
// with progressBar1 do
// begin
// Min:=0;
// Max:=stepcount;
// Step:=1;
With Gauge_process do
begin
Gauge_process.MaxValue:=DBGrid1.Columns.Count*adoquery3.recordcount;
Gauge_process.Progress:=0;
for x:=0 to DBGrid1.Columns.Count-1 do
begin
if DBGrid1.Columns[x].Visible=true Then
begin
adoquery3.First;
for k:=1 To adoquery3.RecordCount Do
begin
ExcelApp.Cells[K+1,x+1]:=''''+adoquery3.FieldByName(DBGrid1.Columns[x].FieldName).Asstring+'';
adoquery3.Next;
Gauge_process.Progress :=Gauge_process.Progress +1;
end;
//j:=j+1;
// Stepit;
// showmessage(''+inttostr(x)+'');
// Gauge_process.Progress :=Gauge_process.Progress +1;
end;
end;
end;
end;
Gauge_process.Visible:=false;
for x:=1 To adoquery3.recordcount+1 Do
ExcelApp.rows[x].Font.SIZE:=10;
ExcelApp.Columns.AutoFit;
ExcelApp.ActiveWorkBook.saveas(filename);
ExcelApp.WorkBooks.Close;
// Application.MessageBox(pchar('数据导出成功,请到【'+filename+'】中查看!'),'数据导出',0);
messagedlg(pchar('数据导出成功,请到【'+filename+'】中查看!'),mtinformation,[mbok],0);
ExcelApp.Quit;
ExcelApp:=Unassigned;
DlgSave.Destroy;
end;
end;
end;
end;
procedure Tf0ch.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
inherited;
if DBGrid1.DataSource.DataSet.RecNo mod 2 = 1 then
begin
DBGrid1.Canvas.Brush.Color :=$00FFFFC2;
dbgrid1.Canvas.Font.Color:=clwindowtext;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end
else
begin
DBGrid1.Canvas.Brush.Color :=$00F2F2F2;
dbgrid1.Canvas.Font.Color:=clwindowtext;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -