不好意思,我很菜,才刚学。
procedure Tfrm_borrow.btn3Click(Sender: TObject);
var
sql:string;
begin
inherited;
if not cdsborrow.Active then Exit;
if THisFuncObj.Confirm(FuncObj,'是否保存?') <> 1 then Exit;
if cdsborrow.State in [dsEdit,dsInsert] then cdsborrow.Post;
if cdsborrow.RecordCount >= 1 then
begin
if not TToolKit.CheckFieldNull(cdsborrow.FieldByName('id').AsString) then
cdsborrow.Delete;
end;
MAINADO.BeginTrans; //数据执行
HisShareFun.ShowWait('正在保存,请稍等....',0,true);
try
try
sql:=' update xm_follow x set x.status = (select status from xm_borrow z where x.type=z.type_id and x.id=z.id) where x.id in (select id from xm_borrow where x.type=type_id )';
THisDbToolKit.ExecSQL(DataObj,sql);
sql:=' update xm_archives y set y.status = (select status from xm_borrow z where y.type=z.type_id and y.id=z.id) where y.id in (select id from xm_borrow where y.type=type_id )';
THisDbToolKit.ExecSQL(DataObj,sql);
cdsborrow.ApplyUpdates(0);
MAINADO.CommitTrans; //数据提交
if cdsborrow.Active then cdsborrow.EmptyDataSet;
THisFuncObj.ShowMSN(FuncObj,'保存成功!','提示',3);
except
on e:Exception do
begin
MAINADO.RollbackTrans;
THisFuncObj.Allart(FuncObj,'保存失败,请联系管理员' + e.Message);
end;
end;
finally
HisShareFun.ShowWait('正在保存,请稍等...',100,false);
end;
btn5.Click;
end;
这时我处理保存的时候。
procedure Tfrm_borrow.btn4Click(Sender: TObject);
begin
inherited;
if not cdsborrow.Active then Exit;
try
cdsborrow.Append;
cdsborrow.FieldByName('id').AsString := '';
cdsborrow.Post;
cxGrid1.SetFocus;
cxGrid1DBBandedTableView1Column1.Focused := True;
except
on e:Exception do
begin
THisFuncObj.Allart(FuncObj,'新增人员失败!' + e.Message);
end;
end;
end;
这是我新增信息的时候,我的想法是,通过一个全部变量,function changedata(var msg:string) :Integer;这是我定义的全局变量,然后我想通过当点击新增的时候,我想置为1,表示可以多条记录新增,但是点击保存的时候,我想置为0,表示不能多条信息同时保存,并提示报错“不能多条信息保存”