📄 reschildfrm.pas
字号:
if (UpperCase(ResDesc.editTableName.Text)=UpperCase('Appequipcopy'))
and(MessageDlg('是否需要统计数量?',mtConfirmation, [mbYes, mbNo], 0) = mrYes)
then
begin
ExcelApp.Cells(1 , 1):='工装编号';
ExcelApp.Cells(1 , 2):='工装名称';
ExcelApp.Cells(1 , 3):='所属图号';
ExcelApp.Cells(1 , 4):='新订货车间';
ExcelApp.Cells(1 , 5):='复制序号';
ExcelApp.Cells(1 , 6):='复制订货单编号';
ExcelApp.Cells(1 , 7):='复制车间';
ExcelApp.Cells(1 , 8):='复制数量';
ExcelApp.Cells(1 , 9):='复制单价';
ExcelApp.Cells(1 , 10):='复制总价';
ExcelApp.Cells(1 , 11):='复制经手人';
ExcelApp.Cells(1 , 12):='复制时间';
ExcelApp.Cells(1 , 13):='报废序号';
ExcelApp.Cells(1 , 14):='报废车间';
ExcelApp.Cells(1 , 15):='报销单编号';
ExcelApp.Cells(1 , 16):='报废数量';
ExcelApp.Cells(1 , 17):='报废单价';
ExcelApp.Cells(1 , 18):='报废总价';
ExcelApp.Cells(1 , 19):='报废经办人';
ExcelApp.Cells(1 , 20):='报废时间';
ExcelApp.Cells(1 , 21):='备注';
COPYNUM:=0;
DISCARDNUM:=0;
COPYTOTALPRICE:=0;
DISCARDTOTALPRICE:=0;
with cdsResQuery do
begin
DisableControls;
i:=2;
First;
while not eof do
begin
ExcelApp.Cells(i , 1):=FieldByName('equipcode').asstring;
ExcelApp.Cells(i , 2):=FieldByName('equipname').asstring;
ExcelApp.Cells(i , 3):=FieldByName('partcode').asstring;
// ExcelApp.Cells(i , 4):=FieldByName('useshop').asstring;
if FieldByName('FLNGCOPYNUM').asinteger<>0 then
begin
if FieldByName('MEM').asinteger=1 then
ExcelApp.Cells(i , 5):=FieldByName('FLNGNO').asstring;
if trim(FieldByName('FSTRCOPYCODE').asstring)<>'' then
ExcelApp.Cells(i , 6):=FieldByName('FSTRCOPYCODE').asstring;
if trim(FieldByName('FSTRCOPYuseshop').asstring)<>'' then
ExcelApp.Cells(i , 7):=FieldByName('FSTRCOPYuseshop').asstring;
ExcelApp.Cells(i , 8):=FieldByName('FLNGCOPYNUM').asstring;
if trim(FieldByName('COPYSINGLEPRICE').asstring)<>'' then
ExcelApp.Cells(i , 9):=FieldByName('COPYSINGLEPRICE').asstring;
ExcelApp.Cells(i , 10):=(FieldByName('COPYSINGLEPRICE').asfloat)*(FieldByName('FLNGCOPYNUM').asfloat);
if trim(FieldByName('FSTRCOPYMAN').asstring)<>'' then
ExcelApp.Cells(i , 11):=FieldByName('FSTRCOPYMAN').asstring;
if trim(FieldByName('FDTMCOPYTIME').asstring)<>'' then
ExcelApp.Cells(i , 12):=FieldByName('FDTMCOPYTIME').asstring;
end;
if FieldByName('FLNGDISCARDNUM').asinteger<>0 then
begin
if trim(FieldByName('FLNGDISCARDNO').asstring)<>'' then
ExcelApp.Cells(i , 13):=FieldByName('FLNGDISCARDNO').asstring;
if trim(FieldByName('FSTRDISCARDSHOP').asstring)<>'' then
ExcelApp.Cells(i , 14):=FieldByName('FSTRDISCARDSHOP').asstring;
if trim(FieldByName('FSTRDISCARDCODE').asstring)<>'' then
ExcelApp.Cells(i , 15):=FieldByName('FSTRDISCARDCODE').asstring;
ExcelApp.Cells(i , 16):=trim(FieldByName('FLNGDISCARDNUM').asstring);
if trim(FieldByName('DISCARDSINGLEPRICE').asstring)<>'' then
ExcelApp.Cells(i , 17):=FieldByName('DISCARDSINGLEPRICE').asstring;
ExcelApp.Cells(i , 18):=(FieldByName('DISCARDSINGLEPRICE').asfloat)*(FieldByName('FLNGDISCARDNUM').asfloat);
if trim(FieldByName('FSTRGDISCARDMAN').asstring)<>'' then
ExcelApp.Cells(i , 19):=FieldByName('FSTRGDISCARDMAN').asstring;
if trim(FieldByName('FDTMGDISCARDTIME').asstring)<>'' then
ExcelApp.Cells(i , 20):=FieldByName('FDTMGDISCARDTIME').asstring;
end;
if FieldByName('MEM').asinteger=0 then
begin
ExcelApp.Cells(i, 21):='新订货';
ExcelApp.Cells(i , 4):=FieldByName('useshop').asstring;
end;
COPYNUM:=COPYNUM+FieldByName('FLNGCOPYNUM').asinteger;
DISCARDNUM:=DISCARDNUM+FieldByName('FLNGDISCARDNUM').asinteger;
COPYTOTALPRICE:=COPYTOTALPRICE+(FieldByName('COPYSINGLEPRICE').asfloat)*(FieldByName('FLNGCOPYNUM').asfloat);
DISCARDTOTALPRICE:=DISCARDTOTALPRICE+(FieldByName('DISCARDSINGLEPRICE').asfloat)*(FieldByName('FLNGDISCARDNUM').asfloat);
i:=i+1;
next;
end;
EnableControls;
ExcelApp.Cells(i , 1):='合计';
ExcelApp.Cells(i , 7):='订货总数';
ExcelApp.Cells(i , 8):=COPYNUM;
ExcelApp.Cells(i , 9):='订货总价';
ExcelApp.Cells(i , 10):=COPYTOTALPRICE;
ExcelApp.Cells(i , 15):='报废总数';
ExcelApp.Cells(i , 16):=DISCARDNUM;
ExcelApp.Cells(i , 17):='报废总价';
ExcelApp.Cells(i , 18):=DISCARDTOTALPRICE;
ExcelApp.Cells(i , 2):='库存数量';
ExcelApp.Cells(i , 3):=inttostr(COPYNUM-DISCARDNUM);
ExcelApp.Cells(i , 5):='库存金额';
ExcelApp.Cells(i , 6):=floattostr(COPYTOTALPRICE-DISCARDTOTALPRICE);
end;
WorkBook.saveas(xlsFileName);
WorkBook.close;
ExcelApp.Quit;
end
else if (UpperCase(ResDesc.editTableName.Text)=UpperCase('GenEquipInfoCOPY'))
and(MessageDlg('是否需要统计数量?',mtConfirmation, [mbYes, mbNo], 0) = mrYes)
then
begin
ExcelApp.Cells(1 , 1):='标准号';
ExcelApp.Cells(1 , 2):='名称及规格';
ExcelApp.Cells(1 , 3):='所属图号';
ExcelApp.Cells(1 , 4):='新订货车间';
ExcelApp.Cells(1 , 5):='复制序号';
ExcelApp.Cells(1 , 6):='复制订货单编号';
ExcelApp.Cells(1 , 7):='复制车间';
ExcelApp.Cells(1 , 8):='复制数量';
ExcelApp.Cells(1 , 9):='复制单价';
ExcelApp.Cells(1 , 10):='复制总价';
ExcelApp.Cells(1 , 11):='复制经手人';
ExcelApp.Cells(1 , 12):='复制时间';
ExcelApp.Cells(1 , 13):='报废序号';
ExcelApp.Cells(1 , 14):='报废车间';
ExcelApp.Cells(1 , 15):='报销单编号';
ExcelApp.Cells(1 , 16):='报废数量';
ExcelApp.Cells(1 , 17):='报废单价';
ExcelApp.Cells(1 , 18):='报废总价';
ExcelApp.Cells(1 , 19):='报废经办人';
ExcelApp.Cells(1 , 20):='报废时间';
ExcelApp.Cells(1 , 21):='备注';
COPYNUM:=0;
DISCARDNUM:=0;
COPYTOTALPRICE:=0;
DISCARDTOTALPRICE:=0;
with cdsResQuery do
begin
DisableControls;
i:=2;
First;
while not eof do
begin
ExcelApp.Cells(i , 1):=FieldByName('equipcode').asstring;
ExcelApp.Cells(i , 2):=FieldByName('equipname').asstring;
ExcelApp.Cells(i , 3):=FieldByName('partcode').asstring;
// ExcelApp.Cells(i , 4):=FieldByName('useshop').asstring;
if FieldByName('FLNGCOPYNUM').asinteger<>0 then
begin
if FieldByName('MEM').asinteger=1 then
ExcelApp.Cells(i , 5):=FieldByName('FLNGNO').asstring;
if trim(FieldByName('FSTRCOPYCODE').asstring)<>'' then
ExcelApp.Cells(i , 6):=FieldByName('FSTRCOPYCODE').asstring;
if trim(FieldByName('FSTRCOPYuseshop').asstring)<>'' then
ExcelApp.Cells(i , 7):=FieldByName('FSTRCOPYuseshop').asstring;
ExcelApp.Cells(i , 8):=FieldByName('FLNGCOPYNUM').asstring;
if trim(FieldByName('COPYSINGLEPRICE').asstring)<>'' then
ExcelApp.Cells(i , 9):=FieldByName('COPYSINGLEPRICE').asstring;
ExcelApp.Cells(i , 10):=(FieldByName('COPYSINGLEPRICE').asfloat)*(FieldByName('FLNGCOPYNUM').asfloat);
if trim(FieldByName('FSTRCOPYMAN').asstring)<>'' then
ExcelApp.Cells(i , 11):=FieldByName('FSTRCOPYMAN').asstring;
if trim(FieldByName('FDTMCOPYTIME').asstring)<>'' then
ExcelApp.Cells(i , 12):=FieldByName('FDTMCOPYTIME').asstring;
end;
if FieldByName('FLNGDISCARDNUM').asinteger<>0 then
begin
if trim(FieldByName('FLNGDISCARDNO').asstring)<>'' then
ExcelApp.Cells(i , 13):=FieldByName('FLNGDISCARDNO').asstring;
if trim(FieldByName('FSTRDISCARDSHOP').asstring)<>'' then
ExcelApp.Cells(i , 14):=FieldByName('FSTRDISCARDSHOP').asstring;
if trim(FieldByName('FSTRDISCARDCODE').asstring)<>'' then
ExcelApp.Cells(i , 15):=FieldByName('FSTRDISCARDCODE').asstring;
ExcelApp.Cells(i , 16):=trim(FieldByName('FLNGDISCARDNUM').asstring);
if trim(FieldByName('DISCARDSINGLEPRICE').asstring)<>'' then
ExcelApp.Cells(i , 17):=FieldByName('DISCARDSINGLEPRICE').asstring;
ExcelApp.Cells(i , 18):=(FieldByName('DISCARDSINGLEPRICE').asfloat)*(FieldByName('FLNGDISCARDNUM').asfloat);
if trim(FieldByName('FSTRGDISCARDMAN').asstring)<>'' then
ExcelApp.Cells(i , 19):=FieldByName('FSTRGDISCARDMAN').asstring;
if trim(FieldByName('FDTMGDISCARDTIME').asstring)<>'' then
ExcelApp.Cells(i , 20):=FieldByName('FDTMGDISCARDTIME').asstring;
end;
if FieldByName('MEM').asinteger=0 then
begin
ExcelApp.Cells(i, 21):='新订货';
ExcelApp.Cells(i , 4):=FieldByName('useshop').asstring;
end;
COPYNUM:=COPYNUM+FieldByName('FLNGCOPYNUM').asinteger;
DISCARDNUM:=DISCARDNUM+FieldByName('FLNGDISCARDNUM').asinteger;
COPYTOTALPRICE:=COPYTOTALPRICE+(FieldByName('COPYSINGLEPRICE').asfloat)*(FieldByName('FLNGCOPYNUM').asfloat);
DISCARDTOTALPRICE:=(FieldByName('DISCARDSINGLEPRICE').asfloat)*(FieldByName('FLNGDISCARDNUM').asfloat);
i:=i+1;
next;
end;
EnableControls;
ExcelApp.Cells(i , 1):='合计';
ExcelApp.Cells(i , 7):='订货总数';
ExcelApp.Cells(i , 8):=COPYNUM;
ExcelApp.Cells(i , 9):='订货总价';
ExcelApp.Cells(i , 10):=COPYTOTALPRICE;
ExcelApp.Cells(i , 15):='报废总数';
ExcelApp.Cells(i , 16):=DISCARDNUM;
ExcelApp.Cells(i , 17):='报废总价';
ExcelApp.Cells(i , 18):=DISCARDTOTALPRICE;
ExcelApp.Cells(i , 2):='库存数量';
ExcelApp.Cells(i , 3):=inttostr(COPYNUM-DISCARDNUM);
ExcelApp.Cells(i , 5):='库存金额';
ExcelApp.Cells(i , 6):=floattostr(COPYTOTALPRICE-DISCARDTOTALPRICE);
end;
WorkBook.saveas(xlsFileName);
WorkBook.close;
ExcelApp.Quit;
end
else
begin
ExcelApp.WorkBooks[1].WorkSheets[1].Name := 'Grid Data';
wwDBGrid1.DataSource.DataSet.DisableControls;
bm := wwDBGrid1.DataSource.DataSet.GetBookmark;
wwDBGrid1.DataSource.DataSet.First;
// First we send the data to a memo
// works faster than doing it directly to Excel
mem := TMemo.Create(Self);
mem.Visible := false;
mem.Parent := MainForm;
mem.Clear;
sline := '';
// add the info for the column names
for col := 0 to wwDBGrid1.FieldCount-1 do
sline := sline + wwDBGrid1.Fields[col].DisplayLabel + #9;
mem.Lines.Add(sline);
// get the data into the memo
for row := 0 to wwDBGrid1.DataSource.DataSet.RecordCount-1 do
begin
sline := '';
for col := 0 to wwDBGrid1.FieldCount-1 do
sline := sline + wwDBGrid1.Fields[col].AsString + #9;
mem.Lines.Add(sline);
wwDBGrid1.DataSource.DataSet.Next;
end;
// we copy the data to the clipboard
mem.SelectAll;
mem.CopyToClipboard;
// if needed, send it to Excel
// if not, we already have it in the clipboard
ExcelApp.Workbooks[1].WorkSheets['Grid Data'].Paste;
WorkBook.saveas(xlsFileName);
WorkBook.close;
ExcelApp.Quit;
FreeAndNil(mem);
wwDBGrid1.DataSource.DataSet.GotoBookmark(bm);
wwDBGrid1.DataSource.DataSet.FreeBookmark(bm);
wwDBGrid1.DataSource.DataSet.EnableControls;
end;
Screen.Cursor := crDefault;
end;
end;
procedure TResChild.wwDBGrid1CalcTitleImage(Sender: TObject; Field: TField;
var TitleImageAttributes: TwwTitleImageAttributes);
begin
if (cdsResQuery.IndexFieldCount<>0)and(Field=cdsResQuery.indexFields[0]) then
TitleImageAttributes.imageIndex:= 55
else
TitleImageAttributes.imageIndex:= -1;
end;
procedure TResChild.CheckBox1Click(Sender: TObject);
var
sql:string;
begin
if ((UpperCase(ResDesc.editTableName.Text)=UpperCase('Appequipcopy'))
or(UpperCase(ResDesc.editTableName.Text)=UpperCase('GenEquipInfoCOPY')))
and(CheckBox1.Checked)and(CheckBox2.Checked) then
begin
CheckBox2.Checked:=false;
CheckBox2Click(self);
end;
if UpperCase(ResDesc.editTableName.Text)=UpperCase('Appequipcopy') then
begin
sql:='';
sql:='(select * from appequipcopy)union (SELECT ';
sql:=sql+''''+''+''' as flngEnterResID,';
sql:=sql+'equipcode,equipname,partcode,useshop,';
sql:=sql+''''+''+''' as FLNGNO,';
sql:=sql+''''+''+''' as FSTRCOPYCODE,';
sql:=sql+''''+''+''' as FSTRCOPYuseshop,';
sql:=sql+'orderamoun as FLNGCOPYNUM,';
sql:=sql+'SINGLEPRICE as COPYSINGLEPRICE,';
sql:=sql+''''+''+''' as FSTRCOPYMAN,';
sql:=sql+'ordertime as FDTMCOPYTIME,';
sql:=sql+''''+''+''' as FLNGDISCARDNO,';
sql:=sql+''''+''+''' as FSTRDISCARDSHOP,';
sql:=sql+''''+''+''' as FSTRDISCARDCODE,';
sql:=sql+''''+''+''' as FLNGDISCARDNUM,';
sql:=sql+''''+''+''' as DISCARDSINGLEPRICE,';
sql:=sql+''''+''+''' as FSTRGDISCARDMAN,';
sql:=sql+'ordertime as FDTMGDISCARDTIME,';
sql:=sql+''''+''+''' as FLNGSTOCKNUM,';
sql:=sql+''''+''+''' as FDBLSTOCKPRICE,';
sql:=sql+''''+''+''' as MEM';
sql:=sql+' from appequip where (orderamoun is not null)and(orderamoun<>0))';
end
ELSE
if UpperCase(ResDesc.editTableName.Text)=UpperCase('GenEquipInfoCOPY') then
begin
sql:='';
sql:='(select * from GenEquipInfoCOPY)union (SELECT ';
sql:=sql+''''+''+''' as flngEnterResID,';
sql:=sql+'equipcode,equipname,partcode,useshop,';
sql:=sql+''''+''+''' as FLNGNO,';
sql:=sql+''''+''+''' as FSTRCOPYCODE,';
sql:=sql+''''+''+''' as FSTRCOPYuseshop,';
sql:=sql+'orderamoun as FLNGCOPYNUM,';
sql:=sql+'SINGLEPRICE as COPYSINGLEPRICE,';
sql:=sql+''''+''+''' as FSTRCOPYMAN,';
sql:=sql+'ordertime as FDTMCOPYTIME,';
sql:=sql+''''+''+''' as FLNGDISCARDNO,';
sql:=sql+''''+''+''' as FSTRDISCARDSHOP,';
sql:=sql+''''+''+''' as FSTRDISCARDCODE,';
sql:=sql+''''+''+''' as FLNGDISCARDNUM,';
sql:=sql+''''+''+''' as DISCARDSINGLEPRICE,';
sql:=sql+''''+''+''' as FSTRGDISCARDMAN,';
sql:=sql+'ordertime as FDTMGDISCARDTIME,';
sql:=sql+''''+''+''' as FLNGSTOCKNUM,';
sql:=sql+''''+''+''' as FDBLSTOCKPRICE,';
sql:=sql+''''+''+''' as MEM';
sql:=sql+' from GenEquipInfo where (orderamoun is not null)and(orderamoun<>0))';
end;
with cdsResQuery do
begin
Filtered:=False;
Close;
if CheckBox1.Checked then
begin
if (UpperCase(ResDesc.editTableName.Text)=UpperCase('Appequipcopy'))
or(UpperCase(ResDesc.editTableName.Text)=UpperCase('GenEquipInfoCOPY')) then
CommandText:= sql
else
CommandText:= 'Select * From ' + TableName
end
else
// CommandText:= 'Select top 40 * From ' + TableName;
CommandText:=FullSQL;//ResDesc.DBMemo1.Lines.Text;
open;
Label1.Visible:=true;
Label2.Visible:=true;
Edit1.Visible:=true;
Edit1.text:=inttostr(recordcount);
end;
end;
procedure TResChild.CheckBox2Click(Sender: TObject);
var
Filterstr,Filterstr1:string;
begin
if CheckBox2.Checked then
begin
frmAppEquipHlp.Notebook1.PageIndex:=1;
frmAppEquipHlp.ShowModal;
Filterstr:='((FDTMCOPYTIME >'''+datetostr(frmAppEquipHlp.FDTMCOPYTIME1.date)+''')and(FDTMCOPYTIME<'''+datetostr(frmAppEquipHlp.FDTMCOPYTIME2.date)+'''))';
if frmAppEquipHlp.cFDTMGDISCARDTIME.ItemIndex=0 then
Filterstr:=Filterstr+'and((FDTMGDISCARDTIME >='''+datetostr(frmAppEquipHlp.FDTMGDISCARDTIME1.date)+''')and(FDTMGDISCARDTIME<='''+datetostr(frmAppEquipHlp.FDTMGDISCARDTIME2.date)+'''))'
else
Filterstr:=Filterstr+'or((FDTMGDISCARDTIME >='''+datetostr(frmAppEquipHlp.FDTMGDISCARDTIME1.date)+''')and(FDTMGDISCARDTIME<='''+datetostr(frmAppEquipHlp.FDTMGDISCARDTIME2.date)+'''))';
with cdsResQuery do
begin
Filterstr1:=Filter;
Filtered:=False;
Filter:=Filterstr;
Filtered:=True;
end;
end
else
begin
cdsResQuery.Filtered:=False;
cdsResQuery.Filter:='';
cdsResQuery.Filtered:=True;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -