唉,跟我的一样,也是第一个不执行,第二个执行了!如下:
procedure TFrm_zzry.BitBtn4Click(Sender: TObject);
var
vygbh:string;
begin
//dmconnectiondb.ADOCn.BeginTrans;
try
setbutton;
setgroupbox;
if flag='addnew' then
begin
//*************新增数据至T_person*****************
with dmconnectiondb.adoqperson do
begin
close;
sql.Clear;
sql.Add('insert into t_person');
sql.Add('values
gh,:bmmc,:xm,:xb,:csrq,:jg,:sfzhm,:mz,:zz,:major,:linkman,:linkphone,:xueli,:likeit,:address,:jkzk,:married,:zzmm)');
parameters.ParamByName('gh').value:=trim(edit6.Text);
parameters.ParamByName('bmmc').value:=trim(combobox9.Text);
parameters.ParamByName('zz').value:=trim(combobox18.Text);
parameters.ParamByName('xm').value:=trim(edit1.Text);
parameters.ParamByName('xb').value:=trim(combobox1.text);
parameters.ParamByName('jg').value:=trim(combobox2.Text);
parameters.ParamByName('sfzhm').value:=trim(edit2.Text);
parameters.ParamByName('csrq').value:=DateToStr(datetimepicker2.Date);
parameters.ParamByName('address').value:=trim(edit3.Text);
parameters.ParamByName('linkman').value:=trim(edit4.Text);
parameters.ParamByName('linkphone').value:=trim(edit5.Text);
parameters.ParamByName('married').value:=trim(combobox4.Text);
parameters.ParamByName('jkzk').value:=trim(edit7.Text);
parameters.ParamByName('zzmm').value:=trim(combobox3.Text);
parameters.ParamByName('mz').value:=trim(combobox5.Text);
parameters.ParamByName('xueli').value:=trim(combobox6.Text);
parameters.ParamByName('major').value:=trim(combobox7.Text);
parameters.ParamByName('likeit').value:=trim(combobox8.Text);
if not prepared then
prepared;
ExecSQL;
end;
//*********新增数据至t_person_detail***************//
with dmconnectiondb.adoqperson_detail do
begin
close;
sql.Clear;
sql.Add('insert t_person_detail');
sql.Add('values
gh,:kh,:zw,:gz,:rzrq,:jxfs,:ssbh,:ch,:ycjb,:mjjb,:mk,:slyy,:fj2,:fj3,:fj4,:fj5,:fj6)');
parameters.ParamByName('gh').value:=trim(edit6.Text);
parameters.ParamByName('kh').value:=trim(edit8.Text);
parameters.ParamByName('zw').value:=trim(combobox10.Text);
parameters.ParamByName('gz').value:=trim(combobox11.Text);
parameters.ParamByName('rzrq').value:=DateToStr(datetimepicker1.Date);
parameters.ParamByName('jxfs').value:=trim(combobox12.Text);
parameters.ParamByName('ssbh').value:=trim(combobox13.Text);
parameters.ParamByName('ch').value:=trim(combobox14.Text);
parameters.ParamByName('ycjb').value:=trim(combobox15.Text);
parameters.ParamByName('mjjb').value:=trim(combobox16.Text);
parameters.ParamByName('mk').value:=trim(combobox17.Text);
parameters.ParamByName('slyy').value:=trim(edit9.Text);
parameters.ParamByName('fj2').value:=trim(edit10.Text);
parameters.ParamByName('fj3').value:=trim(edit11.Text);
parameters.ParamByName('fj4').value:=trim(edit12.Text);
parameters.ParamByName('fj5').value:=trim(edit13.Text);
parameters.ParamByName('fj6').value:=trim(edit14.Text);
if not prepared then
prepared;
ExecSQL;
end;
MessageBox(handle,'员工资料已经保存成功!','电脑提醒您!',MB_OK);
End
else
begin
vygbh:=edit6.text; //修改员工基本资料数据;
with dmconnectiondb.adoqperson do
begin
Close;
SQL.Clear;
SQL.Add('update t_person set');
sql.Add('gh=:gh,bmmc=:bmmc,xm=:xm,xb=:xb,zz=:zz,csrq=:csrq,jg=:jg,sfzhm=:sfzhm,mz=:mz,');
sql.add('major=:major,linkman=:linkman,linkphone=:linkphone,');
sql.add('xueli=:xueli,likeit=:likeit,address=:address,jkzk=:jkzk,');
sql.add('married=:married,zzmm=:zzmm');
SQL.Add('where');
SQL.Add('gh='''+trim(vygbh)+'''');
parameters.ParamByName('gh').value:=trim(edit6.Text);
parameters.ParamByName('bmmc').value:=trim(combobox9.Text);
parameters.ParamByName('zz').value:=trim(combobox18.Text);
parameters.ParamByName('xm').value:=trim(edit1.Text);
parameters.ParamByName('xb').value:=trim(combobox1.text);
parameters.ParamByName('jg').value:=trim(combobox2.Text);
parameters.ParamByName('sfzhm').value:=trim(edit2.Text);
parameters.ParamByName('csrq').value:=DateToStr(datetimepicker2.Date);
parameters.ParamByName('address').value:=trim(edit3.Text);
parameters.ParamByName('linkman').value:=trim(edit4.Text);
parameters.ParamByName('linkphone').value:=trim(edit5.Text);
parameters.ParamByName('married').value:=trim(combobox4.Text);
parameters.ParamByName('jkzk').value:=trim(edit7.Text);
parameters.ParamByName('zzmm').value:=trim(combobox3.Text);
parameters.ParamByName('mz').value:=trim(combobox5.Text);
parameters.ParamByName('xueli').value:=trim(combobox6.Text);
parameters.ParamByName('major').value:=trim(combobox7.Text);
parameters.ParamByName('likeit').value:=trim(combobox8.Text);
ExecSQL;
end;
with dmconnectiondb.adoqperson do //修改员工明细资料数据;
begin
Close;
SQL.Clear;
SQL.Add('update t_person_detail set');
sql.Add('gh=:gh,kh=:kh,zw=:zw,gz=:gz,rzrq=:rzrq,jxfs=:jxfs,ssbh=:ssbh,ch=:ch,');
sql.add('ycjb=:ycjb,mjjb=:mjjb,mk=:mk,');
sql.add('slyy=:slyy,fj2=:fj2,fj3=:fj3,fj4=:fj4,');
sql.add('fj5=:fj5,fj6=:fj6');
SQL.Add('where');
SQL.Add('gh='''+trim(vygbh)+'''');
parameters.ParamByName('gh').value:=trim(edit6.Text);
parameters.ParamByName('kh').value:=trim(edit8.Text);
parameters.ParamByName('zw').value:=trim(combobox10.Text);
parameters.ParamByName('gz').value:=trim(combobox11.Text);
parameters.ParamByName('rzrq').value:=DateToStr(datetimepicker1.Date);
parameters.ParamByName('jxfs').value:=trim(combobox12.Text);
parameters.ParamByName('ssbh').value:=trim(combobox13.Text);
parameters.ParamByName('ch').value:=trim(combobox14.Text);
parameters.ParamByName('ycjb').value:=trim(combobox15.Text);
parameters.ParamByName('mjjb').value:=trim(combobox16.Text);
parameters.ParamByName('mk').value:=trim(combobox17.Text);
parameters.ParamByName('slyy').value:=trim(edit9.Text);
parameters.ParamByName('fj2').value:=trim(edit10.Text);
parameters.ParamByName('fj3').value:=trim(edit11.Text);
parameters.ParamByName('fj4').value:=trim(edit12.Text);
parameters.ParamByName('fj5').value:=trim(edit13.Text);
parameters.ParamByName('fj6').value:=trim(edit14.Text);
ExecSQL;
MessageBox(handle,'员工资料已经修改成功!','电脑提醒您!',MB_OK);
end;
end;
dmconnectiondb.adocn.CommitTrans;
except
begin
// dmconnectiondb.ADOCn.RollbackTrans;
messagebox(handle,'员工编号和卡号必须唯一,数据保存失败!','电脑提醒您!',mb_iconinformation+mb_ok);
end;
end;
end;