📄 addbalance.pas
字号:
unit addBalance;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables,IdGlobal;
type
TfrmAddBalance = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
GroupBox1: TGroupBox;
DBGrid1: TDBGrid;
GroupBox2: TGroupBox;
Label1: TLabel;
id: TEdit;
sum: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function isMoney(s:string):boolean;
public
{ Public declarations }
end;
var
frmAddBalance: TfrmAddBalance;
implementation
{$R *.dfm}
procedure TfrmAddBalance.Button1Click(Sender: TObject);
var
i:integer;
canAdd:boolean;
balance,deficiency:integer;
begin
{检查"会员编号"}
canAdd:=false;
i:=strtoInt(id.Text);
with table1 do
begin
first;
while not eof do
begin
if fields.FieldByName('会员编号').AsInteger=i then
begin
canAdd:=true;
break;
end;
next;
end;
end;
if canAdd=false then
begin
messageDlg('"会员编号"输入错误,请重试!',mtWarning,[mbOk],0);
abort;
end;
{检查"充值金额"}
if isMoney(sum.Text)=false then
begin
messageDlg('"充值金额"输入错误,请重试!',mtWarning,[mbOk],0);
abort;
end;
with table1 do
begin
edit;
balance:=fields.fieldByName('结余').AsInteger;
deficiency:=fields.fieldByName('欠款').AsInteger;
deficiency:=deficiency-strToInt(sum.Text);
if deficiency<=0 then//没有欠款了
begin
balance:=0-deficiency+balance;
deficiency:=0;
end
else balance:=0;
fieldValues['结余']:=balance;
fieldValues['欠款']:=deficiency;
post;
end;
messageDlg('您现在的结余是:'+intToStr(balance)+
'元 欠款是:'+intToStr(deficiency)+'元',mtWarning,[mbOk],0);
id.Text:='';
sum.Text:='';
end;
function TfrmAddBalance.isMoney(s: string): boolean;
var
i:integer;
begin
if length(s)=0 then
begin
result:=false;
exit;
end;
i:=1;
while i<=length(s) do
begin
if (isNumeric(s[i])=false) and (s[i]<>'.') then
begin
result:=false;
exit;
end;
i:=i+1;
end;
result:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -