您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Delphi >> 请大伙帮看一看,一按钮多任务,为什么出现好多错误?

请大伙帮看一看,一按钮多任务,为什么出现好多错误?

来源:网络整理     时间:2016/8/12 14:22:14     关键词:

关于网友提出的“ 请大伙帮看一看,一按钮多任务,为什么出现好多错误?”问题疑问,本网通过在网上对“ 请大伙帮看一看,一按钮多任务,为什么出现好多错误?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 请大伙帮看一看,一按钮多任务,为什么出现好多错误?
描述:

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.z />           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;
这是一个"录入"按钮的单击事件,完成的任务是将本窗口中的数据填入数据库中,然后再得到另一个表中的数据进行计算放入变量中,然后再更新到另一个表中.请大家帮看一看为什么出错,为什么更新不了????


解决方案1:

代码太乱。。看都不想看。。
抽象一点。。。


以上介绍了“ 请大伙帮看一看,一按钮多任务,为什么出现好多错误?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3227516.html

相关图片

相关文章