📄 csh510_04.pas
字号:
if edtBillNo.Text='' then
begin
ShowMsg('UMS10000159'); //票据编号不能为空
edtBillNo.SetFocus;
Abort;
end;
try
StrToInt(edtBillNo.Text); //单据编号
except
ShowMsg('UMS10000160'); //无效的票据编号,编号只能为数字
edtBillNo.SetFocus;
Abort;
end;
if StrToInt(edtBillNo.Text)<=0 then
begin
ShowMsg('UMS10000161'); //无效的票据编号,编号不能为负数或零
edtBillNo.SetFocus;
Abort;
end;
//如果单据编号没有修改,则不检查票据编号是否重复
if AOldBillNo<>StrToInt(edtBillNo.Text) then
begin
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select 1 from CSH510A where C510A_010='+GetDateString(edtDate.Date)+' and C510A_002='+edtBillNo.Text);
SYSDM.qryQuery.Open;
if not SYSDM.qryQuery.IsEmpty then
begin
ShowMsg('UMS10000162'); //票据编号重复,请重新输入
edtBillNo.SetFocus;
Abort;
end;
end;
//检验日期的合法性
if edtDate.Text='' then
begin
ShowMsg('UMS10000163'); //日期不能为空
edtDate.SetFocus;
Abort;
end;
if (edtDate.Date<AOutStartDate) or (edtDate.Date<AInStartDate) then
begin
ShowMsg('UMS10000171'); //日期不能小于转出或转入帐户的建帐日期
edtDate.SetFocus;
Abort;
end;
//检验金额的合法性
if edtAmount.Text='' then
begin
ShowMsg('UMS10000167'); //金额不能为空
edtAmount.SetFocus;
Abort;
end;
try
StrToFloat(edtAmount.Text);
except
ShowMsg('UMS10000166'); //无效的金额,金额只能为数字
edtAmount.SetFocus;
Abort;
end;
if StrToFloat(edtAmount.Text)=0 then
begin
ShowMsg('UMS10000167'); //金额不能为零
edtAmount.SetFocus;
Abort;
end;
//允许记帐时收入支出金额为负数
if GetSysParams('CSH0002')='N' then
begin
if StrToFloat(edtAmount.Text)<0 then
begin
ShowMsg('UMS10000186'); //金额不能为负数
edtAmount.SetFocus;
Abort;
end;
end;
//取得帐户的余额
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select top 1 C510A_013 from CSH510A where C510A_003='+IntToStr(AOutAccNo)+' order by C510A_003, C510A_004 desc, C510A_010 desc');
SYSDM.qryQuery.Open;
ABalance:=SYSDM.qryQuery.Fields[0].Value;
if AMode='ADD' then
begin
//允许帐户余额为负数
if GetSysParams('CSH0001')='N' then
begin
if StrToFloat(edtAmount.Text)>ABalance then
begin
ShowMsg('UMS10000168'); //金额不能大于帐户余额
edtAmount.SetFocus;
Abort;
end;
end;
end
else if AMode='UPD' then
begin
//允许帐户余额为负数
if GetSysParams('CSH0001')='N' then
begin
if StrToFloat(edtAmount.Text)-AOldAmount>ABalance then
begin
ShowMsg('UMS10000168'); //金额不能大于帐户余额
edtAmount.SetFocus;
Abort;
end;
end;
end;
//保存数据
try
Screen.Cursor:=crHourGlass;
SYSDM.ADOC.BeginTrans;
//插入到出纳帐本(转出帐户)
SaveData(AOutAccNo,1);
showmessage('1');
//插入到出纳帐本(转入帐户)
SaveData(AInAccNo,0);
showmessage('2');
SYSDM.ADOC.CommitTrans;
Screen.Cursor:=crDefault;
except
SYSDM.ADOC.RollbackTrans;
ShowMsg(SYSDM.ADOC.Errors[0].Description,1);
Abort;
end;
//新增模式下则继续新增下一条记录,否则关闭
if AMode='ADD' then
begin
SetEmptyInit;
cbFromAcc.SetFocus;
end else
begin
Close;
end;
inherited;
end;
procedure TCsh510_04Form.edtDateCloseUp(Sender: TObject);
begin
inherited;
//取票据编号
edtBillNo.Text:=GetBillNo(edtDate.Date);
end;
procedure TCsh510_04Form.edtDateExit(Sender: TObject);
begin
inherited;
//取票据编号
edtBillNo.Text:=GetBillNo(edtDate.Date);
end;
procedure TCsh510_04Form.SetEmptyInit;
begin
cbFromAcc.ItemIndex:=0;
cbToAcc.ItemIndex:=0;
edtRemark.Text:='';
edtDate.Date:=GetServerDate;
edtBillNo.Text:=GetBillNo(edtDate.Date);
edtAmount.Text:='0';
AOldInAccNo:=0;
AOldOutAccNo:=0;
AOldDate:=0;
AOldBillNo:=0;
AOldAmount:=0;
end;
procedure TCsh510_04Form.qryCsh500AfterScroll(DataSet: TDataSet);
var
ADate:TDateTime;
ABillNo:Integer;
begin
inherited;
if qryCsh500.State in [dsInsert,dsEdit] then Exit;
if (qryCsh500.IsEmpty) or (AMode='ADD') then
begin
SetEmptyInit; //初始化
Exit;
end;
ADate:=qryCsh500.FieldByName('C510A_010').Value; //日期
ABillNo:=qryCsh500.FieldByName('C510A_002').Value; //单据编号
if qryCsh500.FieldByName('C510A_005').Value=0 then //收入 转入帐户
begin
AOldInAccNo:=qryCsh500.FieldByName('C510A_003').Value;
qryCsh550.Locate('C550_001',AOldInAccNo,[]);
cbToAcc.ItemIndex:=cbToAcc.Items.IndexOf(qryCsh550.FieldByName('C550_002').Value);
//取转出帐户名称
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select C510A_003 from CSH510A where C510A_003<>'+IntToStr(AOldInAccNo)+' and C510A_010='+GetDateString(ADate)+' and C510A_002='+IntToStr(ABillNo));
SYSDM.qryQuery.Open;
AOldOutAccNo:=SYSDM.qryQuery.FieldByName('C510A_003').Value;
qryCsh550.Locate('C550_001',AOldOutAccNo,[]);
cbFromAcc.ItemIndex:=cbFromAcc.Items.IndexOf(qryCsh550.FieldByName('C550_002').Value);
end
else if qryCsh500.FieldByName('C510A_005').Value=1 then //支出 转出帐户
begin
AOldOutAccNo:=qryCsh500.FieldByName('C510A_003').Value;
qryCsh550.Locate('C550_001',AOldOutAccNo,[]);
cbFromAcc.ItemIndex:=cbFromAcc.Items.IndexOf(qryCsh550.FieldByName('C550_002').Value);
//取转入帐户名称
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select C510A_003 from CSH510A where C510A_003<>'+IntToStr(AOldOutAccNo)+' and C510A_010='+GetDateString(ADate)+' and C510A_002='+IntToStr(ABillNo));
SYSDM.qryQuery.Open;
AOldInAccNo:=qryCsh500.FieldByName('C510A_003').Value;
qryCsh550.Locate('C550_001',AOldInAccNo,[]);
cbToAcc.ItemIndex:=cbToAcc.Items.IndexOf(qryCsh550.FieldByName('C550_002').Value);
end;
edtDate.Date:=qryCsh500.FieldByName('C510A_010').Value; //日期
edtBillNo.Text:=qryCsh500.FieldByName('C510A_002').AsString; //单据编号
edtAmount.Text:=qryCsh500.FieldByName('C510A_009').AsString; //金额
edtRemark.Text:=qryCsh500.FieldByName('C510A_015').AsString; //摘要
AOldInAccNo:=qryCsh500.FieldByName('C510A_003').Value;
AOldOutAccNo:=qryCsh500.FieldByName('C510A_003').Value;
AOldDate:=qryCsh500.FieldByName('C510A_010').Value;
AOldBillNo:=qryCsh500.FieldByName('C510A_002').Value;
AOldAmount:=qryCsh500.FieldByName('C510A_009').Value;
end;
function TCsh510_04Form.GetUserNo(AEngName: string):Integer;
var
AQyery:TADOQuery;
begin
AQyery:=TADOQuery.Create(nil);
AQyery.Connection:=SYSDM.ADOC;
AQyery.Close;
AQyery.SQL.Clear;
AQyery.SQL.Add('select * from SYS500A where S500A_002='+''''+AEngName+'''');
AQyery.Open;
Result:=AQyery.FieldByName('S500A_001').Value;
AQyery:=nil;
AQyery.Free;
end;
initialization
RegisterClass(TCsh510_04Form);
finalization
UnRegisterClass(TCsh510_04Form);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -