📄 upayment.~pas
字号:
unit Upayment;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Grids,uconst;
type
Tfm_payment = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
dp_opentime: TDateTimePicker;
Ed_outunit: TEdit;
Ed_Inunit: TEdit;
ed_bumf: TEdit;
Button1: TButton;
Button2: TButton;
sg: TStringGrid;
cb_item: TComboBox;
Button3: TButton;
Button4: TButton;
Label5: TLabel;
Edit1: TEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure sgDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
procedure sgKeyPress(Sender: TObject; var Key: Char);
procedure sgClick(Sender: TObject);
procedure cb_itemChange(Sender: TObject);
procedure cb_itemExit(Sender: TObject);
procedure sgSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
FID:integer;
public
{ Public declarations }
property ID:integer read FID write FID ;
procedure showitemcell;
end;
var
fm_payment: Tfm_payment;
implementation
uses umain,udm1,ufunction;
{$R *.dfm}
procedure Tfm_payment.showitemcell;
begin
with dm1.tempquery do
begin
close;
sql.Clear;
sql.Add('select center_money,municipality_money,city_money,county_money,self_money,Sum_money');
sql.Add(' from sum_info_payment where ID='+inttostr(ID));
open;
sg.Cells[0,1]:='上级拨款';
if recordcount>0 then
begin
sg.Cells[1,1]:=fieldbyname('Sum_money').AsString ;
sg.Cells[2,1]:=fieldbyname('center_money').AsString ;
sg.Cells[3,1]:=fieldbyname('municipality_money').AsString ;
sg.Cells[4,1]:=fieldbyname('city_money').AsString ;
sg.Cells[5,1]:=fieldbyname('county_money').AsString ;
sg.Cells[6,1]:=fieldbyname('self_money').AsString ;
end
else
begin
sg.Cells[1,1]:='0';
sg.Cells[2,1]:='0';
sg.Cells[3,1]:='0';
sg.Cells[4,1]:='0';
sg.Cells[5,1]:='0';
sg.Cells[6,1]:='0';
end;
close;
sql.Clear;
sql.Add('select iif(isnull(sum(center_money)),0,sum(center_money)) as center_money,iif(isnull(sum(municipality_money)),0,sum(municipality_money)) as municipality_money,iif(isnull(sum(city_money)),0,sum(city_money)) as city_money,');
sql.Add('iif(isnull(sum(county_money)),0,sum(county_money)) as county_money,iif(isnull(sum(self_money)),0,sum(self_money)) as self_money,iif(isnull(sum(sum_money)),0,sum(Sum_money)) as Sum_money ');
sql.Add(' from sum_info_payment where parentno='''+inttostr(ID)+'''');
open;
sg.Cells[0,2]:='已下拨款';
if recordcount>0 then
begin
sg.Cells[1,2]:=fieldbyname('Sum_money').AsString ;
sg.Cells[2,2]:=fieldbyname('center_money').AsString ;
sg.Cells[3,2]:=fieldbyname('municipality_money').AsString ;
sg.Cells[4,2]:=fieldbyname('city_money').AsString ;
sg.Cells[5,2]:=fieldbyname('county_money').AsString ;
sg.Cells[6,2]:=fieldbyname('self_money').AsString ;
end
else
begin
sg.Cells[1,2]:='0';
sg.Cells[2,2]:='0';
sg.Cells[3,2]:='0';
sg.Cells[4,2]:='0';
sg.Cells[5,2]:='0';
sg.Cells[6,2]:='0';
end;
close;
sql.Clear;
sql.Add('select iif(isnull(sum(center_money)),0,sum(center_money)) as center_money,iif(isnull(sum(municipality_money)),0,sum(municipality_money)) as municipality_money,iif(isnull(sum(city_money)),0,sum(city_money)) as city_money,');
sql.Add('iif(isnull(sum(county_money)),0,sum(county_money)) as county_money,iif(isnull(sum(self_money)),0,sum(self_money)) as self_money,iif(isnull(sum(sum_money)),0,sum(Sum_money)) as Sum_money ');
sql.Add(' from sum_info_payment where receive_affirm=true and parentno='''+inttostr(ID)+'''');
open;
sg.Cells[0,3]:='下拨已确认款';
if recordcount>0 then
begin
sg.Cells[1,3]:=fieldbyname('Sum_money').AsString ;
sg.Cells[2,3]:=fieldbyname('center_money').AsString ;
sg.Cells[3,3]:=fieldbyname('municipality_money').AsString ;
sg.Cells[4,3]:=fieldbyname('city_money').AsString ;
sg.Cells[5,3]:=fieldbyname('county_money').AsString ;
sg.Cells[6,3]:=fieldbyname('self_money').AsString ;
end
else
begin
sg.Cells[1,3]:='0';
sg.Cells[2,3]:='0';
sg.Cells[3,3]:='0';
sg.Cells[4,3]:='0';
sg.Cells[5,3]:='0';
sg.Cells[6,3]:='0';
end;
close;
sql.Clear;
sql.Add('select iif(isnull(sum(center_money)),0,sum(center_money)) as center_money,iif(isnull(sum(municipality_money)),0,sum(municipality_money)) as municipality_money,iif(isnull(sum(city_money)),0,sum(city_money)) as city_money,');
sql.Add('iif(isnull(sum(county_money)),0,sum(county_money)) as county_money,iif(isnull(sum(self_money)),0,sum(self_money)) as self_money,iif(isnull(sum(sum_money)),0,sum(Sum_money)) as Sum_money ');
sql.Add(' from sum_info_payment where receive_affirm=false and parentno='''+inttostr(ID)+'''');
open;
sg.Cells[0,4]:='下拨未确认款';
if recordcount>0 then
begin
sg.Cells[1,4]:=fieldbyname('Sum_money').AsString ;
sg.Cells[2,4]:=fieldbyname('center_money').AsString ;
sg.Cells[3,4]:=fieldbyname('municipality_money').AsString ;
sg.Cells[4,4]:=fieldbyname('city_money').AsString ;
sg.Cells[5,4]:=fieldbyname('county_money').AsString ;
sg.Cells[6,4]:=fieldbyname('self_money').AsString ;
end
else
begin
sg.Cells[1,4]:='0';
sg.Cells[2,4]:='0';
sg.Cells[3,4]:='0';
sg.Cells[4,4]:='0';
sg.Cells[5,4]:='0';
sg.Cells[6,4]:='0';
end;
end;
sg.Cells[0,5]:='未下拨款';
sg.Cells[1,5]:=floattostr(strtofloat(sg.Cells[1,1])-strtofloat(sg.Cells[1,2]));
sg.Cells[2,5]:=floattostr(strtofloat(sg.Cells[2,1])-strtofloat(sg.Cells[2,2]));
sg.Cells[3,5]:=floattostr(strtofloat(sg.Cells[3,1])-strtofloat(sg.Cells[3,2]));
sg.Cells[4,5]:=floattostr(strtofloat(sg.Cells[4,1])-strtofloat(sg.Cells[4,2]));
sg.Cells[5,5]:=floattostr(strtofloat(sg.Cells[5,1])-strtofloat(sg.Cells[5,2]));
sg.Cells[6,5]:=floattostr(strtofloat(sg.Cells[6,1])-strtofloat(sg.Cells[6,2]));
end;
procedure Tfm_payment.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
fm_payment:=nil;
end;
procedure Tfm_payment.Button1Click(Sender: TObject);
begin
mainfm.unittree.SetFocus ;
outed:=true;
end;
procedure Tfm_payment.Button2Click(Sender: TObject);
begin
mainfm.unittree.SetFocus ;
outed:=false;
end;
procedure Tfm_payment.FormCreate(Sender: TObject);
begin
dp_opentime.DateTime :=now;
sg.Cells[0,0]:='项目';
sg.ColWidths[0]:=150;
sg.Cells[1,0]:='合计';
sg.ColWidths[1]:=100;
sg.Cells[2,0]:='中央';
sg.ColWidths[2]:=80;
sg.Cells[3,0]:='自治区';
sg.ColWidths[3]:=80;
sg.Cells[4,0]:='市配套';
sg.ColWidths[4]:=80;
sg.Cells[5,0]:='县配套';
sg.ColWidths[5]:=80;
sg.Cells[6,0]:='自筹';
sg.ColWidths[6]:=80;
with dm1.tempquery do
begin
sql.Clear ;
sql.Add('select item_NO,item_name from info_item order by item_NO');
open;
while not eof do
begin
cb_item.Items.Add(fieldbyname('item_no').AsString +BOXSIGN+fieldbyname('item_NAME').AsString);
next;
end;
end;
end;
procedure Tfm_payment.sgDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with (sender as tstringgrid).Canvas do
begin
Brush.Color := clWindow;
Font.Color := clWindowText;
if gdFixed in State then
Brush.Color := (sender as tstringgrid).FixedColor;
if (gdSelected in State) and ((sender as tstringgrid).Focused) then //关键!如果StringGrid失去焦点就不加亮显示
begin
Brush.Color := clHighLight;
Font.Color := clHighLightText;
end;
FillRect(Rect);
with (sender as tstringgrid) do TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
if gdFixed in State then
DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT);
if gdFocused in State then
DrawFocusRect(Rect);
end;
end;
procedure Tfm_payment.sgKeyPress(Sender: TObject; var Key: Char);
begin
if (sg.Col<>0) then //键盘输入事件
begin
if not (key in ['0'..'9',#8]) then
key := #0 ;
end;
if (sg.Row <6) then
key:=#0;
end;
function nulled(text:string):double;
begin
try
if text='' then
result:=0
else
result:=strtofloat(text);
except
result:=0;
end;
end;
procedure Tfm_payment.sgClick(Sender: TObject);
begin
if sg.row>5 then
begin
cb_item.Left:=sg.CellRect(0,sg.Row).Left+10;
cb_item.Top:=sg.cellrect(0,sg.Row).Top+120;
sg.Cells[1,sg.Row]:=floattostr(nulled(sg.cells[2,sg.Row])+nulled(sg.cells[3,sg.Row])+
nulled(sg.cells[4,sg.Row])+nulled(sg.cells[5,sg.Row])+nulled(sg.cells[6,sg.Row]));
end;
end;
procedure Tfm_payment.cb_itemChange(Sender: TObject);
begin
sg.Cells[0,sg.Row]:=cb_item.Items[cb_item.ItemIndex];
sg.SetFocus;
end;
procedure Tfm_payment.cb_itemExit(Sender: TObject);
begin
cb_item.Visible :=false;
end;
procedure Tfm_payment.sgSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
if acol<>0 then
cb_item.Visible :=false
else
cb_item.Visible :=true;
end;
procedure Tfm_payment.Button4Click(Sender: TObject);
begin
close;
end;
procedure Tfm_payment.Button3Click(Sender: TObject);
var
left,rigth:string;
outunitno,outunitname,inunitno,inunitname,datestr:string;
i:integer;
begin
if edit1.Text ='' then
begin
application.MessageBox('文号不能为空','提示',64);
exit;
end;
if ed_bumf.Text ='' then
ed_bumf.Text :=edit1.Text;
cleftstr(ed_outunit.Text,BOXSIGN,left,rigth);
outunitno:=left;
outunitname:=rigth;
cleftstr(ed_inunit.Text,BOXSIGN,left,rigth);
inunitno:=left;
inunitname:=rigth;
datestr:=getdatestr(dp_opentime.Date);
with dm1.paymentquery do
begin
{sql.Clear ;
sql.Add('select max(ID) as a from info_payment');
open;
maxID:=fieldbyname('a').AsInteger+1 ; }
close;
sql.Clear ;
sql.Add('select * from info_payment where bumf_no=''0''');
open;
for i:=6 to sg.RowCount -1 do
begin
if sg.Cells[0,i]<>'' then
begin
cleftstr(sg.Cells[0,i],BOXSIGN,left,rigth);
append;
fieldbyname('bumf_no').AsString :=ed_bumf.Text ;
fieldbyname('parentno').AsString :=inttostr(id) ;
fieldbyname('paymentno').AsString :=edit1.Text;
fieldbyname('out_u_no').AsString :=outunitno;
fieldbyname('out_u_name').AsString :=outunitname;
fieldbyname('in_u_no').AsString :=inunitno;
fieldbyname('in_u_name').AsString :=inunitname;
fieldbyname('date_no').AsString :=datestr;
fieldbyname('payment_time').AsDateTime :=dp_opentime.DateTime;
fieldbyname('item_no').AsString :=left;
fieldbyname('center_money').AsString :=floattostr(nulled(sg.Cells[2,i]));
fieldbyname('municipality_money').AsString :=floattostr(nulled(sg.Cells[3,i]));
fieldbyname('city_money').AsString :=floattostr(nulled(sg.Cells[4,i]));
fieldbyname('county_money').AsString :=floattostr(nulled(sg.Cells[5,i]));
fieldbyname('self_money').AsString :=floattostr(nulled(sg.Cells[6,i]));
post;
end;
end;
close;
end;
close;
end;
procedure Tfm_payment.FormShow(Sender: TObject);
begin
//if ed_bumf.Text ='' then
end;
procedure Tfm_payment.FormPaint(Sender: TObject);
begin
showitemcell;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -