📄 owedetailunit.pas
字号:
Department_ComboBox.ItemIndex:=-1;
Scholarid_edit.Text :='';
Scholar_ComboBox.Itemindex:=-1;
name_Edit.Text :='';
Length_ComboBox.ItemIndex:=-1;
ClassCode_Edit.Text :='';
end;
procedure Towedetailform.FormShow(Sender: TObject);
begin
clearcontent;
end;
procedure Towedetailform.search_bitbtnClick(Sender: TObject);
begin
if (trim( ChargeYearID_edit.Text )='') and (trim(Departmentid_Edit.Text )='')
and (trim(Scholarid_edit.Text )='') and (trim(name_Edit.Text )='')
and (trim(Length_ComboBox.Text )='') and (trim(ClassCode_Edit.Text )='')
and (trim(ChargeRangeId_edit.text)='') then
begin
MessageBox(application.handle,pchar('没有选择查询条件!'),'错误',MB_ICONWARNING+MB_OK);
list_adoquery.close;
clearcontent;
exit;
end;
with list_adoquery do
begin
close;
sql.clear;
if trim(name_Edit.text)='' then
begin
sql.Add('select ');
if trim(ClassCode_Edit.Text )<>'' then
begin
sql.Add('student.studentname as ''姓名'',') ;
sql.add('sum(学费) as 学费,sum(住宿费) as 住宿费,sum(书费) as 书费,sum(保险费) as 保险费,sum(生活用品费) as 生活用品费,sum(保证金) as 保证金,sum(合计) as 合计 from ( ');
end
else if trim(Departmentid_Edit.Text )<>'' then
begin
sql.Add('student.classcode as ''班级'',');
sql.add('sum(学费) as 学费,sum(住宿费) as 住宿费,sum(书费) as 书费,sum(保险费) as 保险费,sum(生活用品费) as 生活用品费,sum(保证金) as 保证金,sum(合计) as 合计 from ( ');
end
else
begin
sql.Add(' department.department as ''院系'',');
sql.add('sum(学费) as 学费,sum(住宿费) as 住宿费,sum(书费) as 书费,sum(保险费) as 保险费,sum(生活用品费) as 生活用品费,sum(保证金) as 保证金,sum(合计) as 合计 from ( ');
end;
sql.add('select a.studentid,a.chargerangeid,a.studyyear,a.owe as ''学费'',b.owe as ''住宿费'',') ;
sql.add('c.owe as ''书费'',d.owe as ''保险费'',e.owe as ''生活用品费'',f.owe as ''保证金'',') ;
sql.add('(a.owe+b.owe+c.owe+e.owe+f.owe+d.owe) as ''合计'' from(') ;
sql.add('select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income ') ;
sql.add('where chargeitemid=1) as a ') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=2) as b on a.studentid=b.studentid and a.chargerangeid=b.chargerangeid and a.studyyear=b.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=3) as c on a.studentid=c.studentid and a.chargerangeid=c.chargerangeid and a.studyyear=c.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=4) as d on a.studentid=d.studentid and a.chargerangeid=d.chargerangeid and a.studyyear=d.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=5) as e on a.studentid=e.studentid and a.chargerangeid=e.chargerangeid and a.studyyear=e.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=6) as f on a.studentid=f.studentid and a.chargerangeid=f.chargerangeid and a.studyyear=f.studyyear)') ;
sql.add('as a,student,department where a.studentid=student.id and student.departmentid=department.id') ;
if trim( ChargeYearID_edit.Text )<>'' then
sql.add(' and student.ChargeYearID='+trim( ChargeYearID_edit.Text ));
if trim( ChargeRangeId_edit.Text )<>'' then
sql.add(' and a.ChargeRangeId='+trim( ChargeRangeId_edit.Text ));
if trim(Departmentid_Edit.Text )<>'' then
sql.add(' and student.departmentid='+trim( Departmentid_Edit.Text ));
if trim(Scholarid_edit.Text )<>'' then
sql.add(' and student.Scholarid='+trim( Scholarid_edit.Text ));
if trim(name_Edit.Text )<>'' then
sql.add(' and student.studentname='''+trim( name_Edit.Text )+'''');
if trim(Length_ComboBox.Text )<>'' then
sql.add(' and student.length='+trim( Length_ComboBox.Text ));
if trim(ClassCode_Edit.Text )<>'' then
sql.add(' and student.classcode='''+trim( ClassCode_Edit.Text )+'''');
if trim(name_Edit.Text)<>'' then sql.Add('')
else if trim(ClassCode_Edit.Text )<>'' then
sql.Add(' group by student.studentname ')
else if trim(Departmentid_Edit.Text )<>'' then
sql.Add(' group by student.classcode ')
else
sql.Add(' group by department.department ');
sql.Add('union all');
sql.Add('select ');
if trim(ClassCode_Edit.Text )<>'' then
begin
sql.Add('''合计'' as ''姓名'',') ;
sql.add('sum(学费) as 学费,sum(住宿费) as 住宿费,sum(书费) as 书费,sum(保险费) as 保险费,sum(生活用品费) as 生活用品费,sum(保证金) as 保证金,sum(合计) as 合计 from ( ');
end
else if trim(Departmentid_Edit.Text )<>'' then
begin
sql.Add('''合计'' as ''班级'',');
sql.add('sum(学费) as 学费,sum(住宿费) as 住宿费,sum(书费) as 书费,sum(保险费) as 保险费,sum(生活用品费) as 生活用品费,sum(保证金) as 保证金,sum(合计) as 合计 from ( ');
end
else
begin
sql.Add('''合计'' as ''院系'',');
sql.add('sum(学费) as 学费,sum(住宿费) as 住宿费,sum(书费) as 书费,sum(保险费) as 保险费,sum(生活用品费) as 生活用品费,sum(保证金) as 保证金,sum(合计) as 合计 from ( ');
end;
sql.add('select a.studentid,a.chargerangeid,a.studyyear,a.owe as ''学费'',b.owe as ''住宿费'',') ;
sql.add('c.owe as ''书费'',d.owe as ''保险费'',e.owe as ''生活用品费'',f.owe as ''保证金'',') ;
sql.add('(a.owe+b.owe+c.owe+e.owe+f.owe+d.owe) as ''合计'' from(') ;
sql.add('select studentid,chargerangeid,studyyear,(quantum-fact-derate+returnnum) as owe') ;
sql.add('from income ') ;
sql.add('where chargeitemid=1) as a ') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=2) as b on a.studentid=b.studentid and a.chargerangeid=b.chargerangeid and a.studyyear=b.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=3) as c on a.studentid=c.studentid and a.chargerangeid=c.chargerangeid and a.studyyear=c.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=4) as d on a.studentid=d.studentid and a.chargerangeid=d.chargerangeid and a.studyyear=d.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=5) as e on a.studentid=e.studentid and a.chargerangeid=e.chargerangeid and a.studyyear=e.studyyear') ;
sql.add('left join') ;
sql.add('(select studentid,chargerangeid,studyyear,(quantum-derate-(fact-returnnum)) as owe') ;
sql.add('from income') ;
sql.add('where chargeitemid=6) as f on a.studentid=f.studentid and a.chargerangeid=f.chargerangeid and a.studyyear=f.studyyear)') ;
sql.add('as a,student,department where a.studentid=student.id and student.departmentid=department.id') ;
if trim( ChargeYearID_edit.Text )<>'' then
sql.add(' and student.ChargeYearID='+trim( ChargeYearID_edit.Text ));
if trim( ChargeRangeId_edit.Text )<>'' then
sql.add(' and a.ChargeRangeId='+trim( ChargeRangeId_edit.Text ));
if trim(Departmentid_Edit.Text )<>'' then
sql.add(' and student.departmentid='+trim( Departmentid_Edit.Text ));
if trim(Scholarid_edit.Text )<>'' then
sql.add(' and student.Scholarid='+trim( Scholarid_edit.Text ));
if trim(name_Edit.Text )<>'' then
sql.add(' and student.studentname='''+trim( name_Edit.Text )+'''');
if trim(Length_ComboBox.Text )<>'' then
sql.add(' and student.length='+trim( Length_ComboBox.Text ));
if trim(ClassCode_Edit.Text )<>'' then
sql.add(' and student.classcode='''+trim( ClassCode_Edit.Text )+'''');
end
else
begin
sql.add('select case chargeitemid when 1 then ''学费'' when 2 then ''住宿'' ');
sql.add('when 3 then ''书费'' when 4 then ''保险'' when 5 then ''生活用品'' when 6 then ''保证金''end as ''项目'',');
sql.add('sum(quantum) as ''应收金额'',sum(fact) as ''实收金额'',sum(derate) as ''减免金额'',sum(returnnum) as ''退费金额'',sum(quantum-derate-(fact-returnnum)) as ''欠费金额''');
sql.add(' from income,student,department where income.studentid=student.id and student.departmentid=department.id');
if trim( ChargeYearID_edit.Text )<>'' then
sql.add(' and student.ChargeYearID='+trim( ChargeYearID_edit.Text ));
if trim( ChargeRangeId_edit.Text )<>'' then
sql.add(' and income.ChargeRangeId='+trim( ChargeRangeId_edit.Text ));
if trim(Departmentid_Edit.Text )<>'' then
sql.add(' and student.departmentid='+trim( Departmentid_Edit.Text ));
if trim(Scholarid_edit.Text )<>'' then
sql.add(' and student.Scholarid='+trim( Scholarid_edit.Text ));
if trim(name_Edit.Text )<>'' then
sql.add(' and student.studentname='''+trim( name_Edit.Text )+'''');
if trim(Length_ComboBox.Text )<>'' then
sql.add(' and student.length='+trim( Length_ComboBox.Text ));
if trim(ClassCode_Edit.Text )<>'' then
sql.add(' and student.classcode='''+trim( ClassCode_Edit.Text )+'''');
sql.add('group by chargeitemid ');
sql.Add('union all');
sql.add('select ''合计'' as ''项目'',');
sql.add('sum(quantum) as ''应收金额'',sum(fact) as ''实收金额'',sum(derate) as ''减免金额'',sum(returnnum) as ''退费金额'',sum(quantum-derate-(fact-returnnum)) as ''欠费金额''');
sql.add(' from income,student,department where income.studentid=student.id and student.departmentid=department.id');
if trim( ChargeYearID_edit.Text )<>'' then
sql.add(' and student.ChargeYearID='+trim( ChargeYearID_edit.Text ));
if trim( ChargeRangeId_edit.Text )<>'' then
sql.add(' and income.ChargeRangeId='+trim( ChargeRangeId_edit.Text ));
if trim(Departmentid_Edit.Text )<>'' then
sql.add(' and student.departmentid='+trim( Departmentid_Edit.Text ));
if trim(Scholarid_edit.Text )<>'' then
sql.add(' and student.Scholarid='+trim( Scholarid_edit.Text ));
if trim(name_Edit.Text )<>'' then
sql.add(' and student.studentname='''+trim( name_Edit.Text )+'''');
if trim(Length_ComboBox.Text )<>'' then
sql.add(' and student.length='+trim( Length_ComboBox.Text ));
if trim(ClassCode_Edit.Text )<>'' then
sql.add(' and student.classcode='''+trim( ClassCode_Edit.Text )+'''');
end;
open;
//memo1.Lines.Text :=sql.Text ;
end;
end;
procedure Towedetailform.ChargeRangeId_editKeyPress(Sender: TObject;
var Key: Char);
begin
if not (key in['0'..'9','.',#8,#13]) then key:=#0;
end;
procedure Towedetailform.ChargeYearID_editKeyPress(Sender: TObject;
var Key: Char);
begin
if not (key in['0'..'9','.',#8,#13]) then key:=#0;
end;
procedure Towedetailform.output_bitbtnClick(Sender: TObject);
begin
ExportToExc(list_adoquery) ;
end;
procedure Towedetailform.ClassCode_EditChange(Sender: TObject);
var i:Integer;
begin
name_Edit.Items.Clear;
if trim(classcode_edit.Text )='' then exit;
with oper_adoquery do
begin
close;
sql.Clear;
sql.Add('select distinct(studentname) as studentn from student where classcode=:classcode');
Parameters.ParamByName('classcode').Value :=trim(classcode_edit.Text );
open;
name_Edit.Items.Add(' ');
if not isempty then
begin
for i := 0 to RecordCount-1 do
begin
name_Edit.Items.Add(fieldbyname('studentn').AsString) ;
Next;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -