procedure Tzhouhuo.BitBtn1Click(Sender: TObject);
var
haszh:boolean;
ii:double;
f1,f2,f3,f4,f5,f6:double;
//是否有走货编号函数
function haszhbh(s1:String):boolean;
begin
if (s1<>'') then
begin
with DataForm.zhouhuoQuery do
begin
close;
sql.Clear;
sql.Add('select * from zhouhuo_info where zh_bianhao='+quotedStr(s1));
open;
Result :=(RecordCount>0);
end;
end
else
showmessage('走货编号不能为空!');
end;
//从窗体中接收数据,然后填进库中
begin
haszh:=haszhbh(trim(edit2.Text));
With DataForm.zhouhuoQuery Do
begin
Close;
Sql.Clear;
Sql.Add('select * from zhouhuo_info,tuoyun_info where tuoyun_info.qd_bianhao = zhouhuo_info.qd_bianhao');
OPen;
if (combobox1.Text='') or (edit2.Text='') or (edit3.Text='') or (edit5.Text='') or (combobox2.Text='') or (edit9.Text='') or (edit10.Text='') or (edit14.Text='') then
begin
showmessage('请将数据填写完整!');
edit2.SetFocus;
end
else
begin
if (Not haszh) then
begin
Append;
FieldByName('zhouhuo_info.qd_bianhao').AsString:=trim(combobox1.Text);
FieldByName('zh_bianhao').AsString:=trim(edit2.Text);
FieldByName('zhouhuo_info.huowumingcheng').AsString:=trim(edit3.Text);
FieldByName('zhongliang').AsString:=trim(edit5.Text);
FieldByName('tiji').AsString:=trim(edit9.Text);
FieldbyName('zhouhuo_info.fahuoriqi').AsString:=FormatDateTime('yyyy-mm-dd', DateTimePicker1.DateTime);
FieldByName('baohao').AsString:=trim(edit10.Text);
FieldByName('dabaoleixing').AsString:=trim(combobox2.Text);
FieldByName('dabaofei').AsFloat:=strtofloat(trim(edit14.Text));
If MessageDlg('是否要把数据写入库中!',MtConfirmation,[mbYes,mbNo],0)=mrYes then
begin
post;
showmessage('数据已成功的写入数据库中!');
end
else
cancel;
end
else
showmessage('走货编号已经存在,请添加其它走货编号!');
end;
//取数据库中相应的数据然后计算放入变量中
try
with DataForm.zhouhuoQuery do
begin
Close;
Sql.Clear;
Sql.Add('select * from zhouhuo_info,tuoyun_info where tuoyun_info.qd_bianhao = zhouhuo_info.qd_bianhao and zhouhuo_info.qd_bianhao='+trim(ComboBox1.Text));
OPen;
ii:=FieldByName('baoshu').AsFloat+1;
f1:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('zhongliang').AsString);
f2:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('tiji').AsString);
f3:=strtofloat(FieldByName('baojiafei').AsString) * strtofloat(FieldByName('ysbxfbl').AsString);
f4:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('syjcfdj').AsString);
f5:=FieldByName('zonglifang').AsFloat * strtofloat(FieldByName('danweiyunfei').AsString);
f6:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('dabaofei').AsString);
post;
end;
//通过计算得出的数据然后回填到数据库中,数据更新
with DataForm.zhouhuoQuery do
begin
Close;
Sql.Clear;
Sql.Add('update tuoyun_info set tuoyun_info.baoshu=:wjz1,tuoyun_info.zongzhongliang=:wjz2,tuoyun_info.zonglifang=:wjz3,tuoyun_info.ysbxf=:wjz4,tuoyun_info.syjcf=:wjz5,tuoyun_info.zongyunfei=:wjz6,tuoyun_info.zongdabaofei=:wjz7 where tuoyun_info.qd_bianhao=:wjz8');
parameters.ParamByName('wjz1').value :=trim(ComboBox1.Text);
parameters.ParamByName('wjz2').value :=ii;
parameters.ParamByName('wjz3').value :=f1;
parameters.ParamByName('wjz4').value :=f2;
parameters.ParamByName('wjz5').value :=f3;
parameters.ParamByName('wjz6').value :=f4;
parameters.ParamByName('wjz7').value :=f5;
parameters.ParamByName('wjz8').value :=f6;
ExecSQL;
end; except
showmessage('数据计算出错!');
end; end;end;这是一个"录入"按钮的单击事件,完成的任务是将本窗口中的数据填入数据库中,然后再得到另一个表中的数据进行计算放入变量中,然后再更新到另一个表中.请大家帮看一看为什么出错,为什么更新不了????
var
haszh:boolean;
ii:double;
f1,f2,f3,f4,f5,f6:double;
//是否有走货编号函数
function haszhbh(s1:String):boolean;
begin
if (s1<>'') then
begin
with DataForm.zhouhuoQuery do
begin
close;
sql.Clear;
sql.Add('select * from zhouhuo_info where zh_bianhao='+quotedStr(s1));
open;
Result :=(RecordCount>0);
end;
end
else
showmessage('走货编号不能为空!');
end;
//从窗体中接收数据,然后填进库中
begin
haszh:=haszhbh(trim(edit2.Text));
With DataForm.zhouhuoQuery Do
begin
Close;
Sql.Clear;
Sql.Add('select * from zhouhuo_info,tuoyun_info where tuoyun_info.qd_bianhao = zhouhuo_info.qd_bianhao');
OPen;
if (combobox1.Text='') or (edit2.Text='') or (edit3.Text='') or (edit5.Text='') or (combobox2.Text='') or (edit9.Text='') or (edit10.Text='') or (edit14.Text='') then
begin
showmessage('请将数据填写完整!');
edit2.SetFocus;
end
else
begin
if (Not haszh) then
begin
Append;
FieldByName('zhouhuo_info.qd_bianhao').AsString:=trim(combobox1.Text);
FieldByName('zh_bianhao').AsString:=trim(edit2.Text);
FieldByName('zhouhuo_info.huowumingcheng').AsString:=trim(edit3.Text);
FieldByName('zhongliang').AsString:=trim(edit5.Text);
FieldByName('tiji').AsString:=trim(edit9.Text);
FieldbyName('zhouhuo_info.fahuoriqi').AsString:=FormatDateTime('yyyy-mm-dd', DateTimePicker1.DateTime);
FieldByName('baohao').AsString:=trim(edit10.Text);
FieldByName('dabaoleixing').AsString:=trim(combobox2.Text);
FieldByName('dabaofei').AsFloat:=strtofloat(trim(edit14.Text));
If MessageDlg('是否要把数据写入库中!',MtConfirmation,[mbYes,mbNo],0)=mrYes then
begin
post;
showmessage('数据已成功的写入数据库中!');
end
else
cancel;
end
else
showmessage('走货编号已经存在,请添加其它走货编号!');
end;
//取数据库中相应的数据然后计算放入变量中
try
with DataForm.zhouhuoQuery do
begin
Close;
Sql.Clear;
Sql.Add('select * from zhouhuo_info,tuoyun_info where tuoyun_info.qd_bianhao = zhouhuo_info.qd_bianhao and zhouhuo_info.qd_bianhao='+trim(ComboBox1.Text));
OPen;
ii:=FieldByName('baoshu').AsFloat+1;
f1:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('zhongliang').AsString);
f2:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('tiji').AsString);
f3:=strtofloat(FieldByName('baojiafei').AsString) * strtofloat(FieldByName('ysbxfbl').AsString);
f4:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('syjcfdj').AsString);
f5:=FieldByName('zonglifang').AsFloat * strtofloat(FieldByName('danweiyunfei').AsString);
f6:=FieldByName('baoshu').AsFloat * strtofloat(FieldByName('dabaofei').AsString);
post;
end;
//通过计算得出的数据然后回填到数据库中,数据更新
with DataForm.zhouhuoQuery do
begin
Close;
Sql.Clear;
Sql.Add('update tuoyun_info set tuoyun_info.baoshu=:wjz1,tuoyun_info.zongzhongliang=:wjz2,tuoyun_info.zonglifang=:wjz3,tuoyun_info.ysbxf=:wjz4,tuoyun_info.syjcf=:wjz5,tuoyun_info.zongyunfei=:wjz6,tuoyun_info.zongdabaofei=:wjz7 where tuoyun_info.qd_bianhao=:wjz8');
parameters.ParamByName('wjz1').value :=trim(ComboBox1.Text);
parameters.ParamByName('wjz2').value :=ii;
parameters.ParamByName('wjz3').value :=f1;
parameters.ParamByName('wjz4').value :=f2;
parameters.ParamByName('wjz5').value :=f3;
parameters.ParamByName('wjz6').value :=f4;
parameters.ParamByName('wjz7').value :=f5;
parameters.ParamByName('wjz8').value :=f6;
ExecSQL;
end; except
showmessage('数据计算出错!');
end; end;end;这是一个"录入"按钮的单击事件,完成的任务是将本窗口中的数据填入数据库中,然后再得到另一个表中的数据进行计算放入变量中,然后再更新到另一个表中.请大家帮看一看为什么出错,为什么更新不了????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货