var a,b:integer;
begin
For a:=1 to StrToInt(Edit2.Text) do
begin
 with Adoquery2 do   //保存主表信息
    begin
      Close;
      SQl.Clear;
      SQl.Add('select * from fj');
      open;
      insert;
      FieldByName('fj').AsString:=edit1.Text+'0'+IntToStr(a);
      FieldByName('kd').AsString:=edit3.Text;
      post;
    end;
        with Adoquery4 do
    begin
      Close;
      SQl.Clear;
       SQl.Add('select * from bomindex where name = :b');
        parameters.ParamByName('b').Value:=''+Edit1.Text+'';
      open;
      Edit;
      FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit4.Text)-strtofloat(Edit3.Text)]));
      updaterecord;
      post;
    end;
end;
end;

解决方案 »

  1.   

    如图所示想把卷号00001切成3卷
    For a:=1 to StrToInt(Edit2.Text) do 
    begin 
     with Adoquery2 do   //保存主表信息 
        begin 
          Close; 
          SQl.Clear; 
          SQl.Add('select * from fj'); 
          open; 
          insert; 
          FieldByName('fj').AsString:=edit1.Text+'0'+IntToStr(a); 
          FieldByName('kd').AsString:=edit3.Text; 
          post; 
        end; 
    通过上述得到
    a=3
    edit1.Text=00001 edit3.Text=20
    确定后得到     
               分卷号       宽度
              0000101       20
             0000102       20
             0000103      20这实现成功了,没问题
     with Adoquery4 do 
        begin 
          Close; 
          SQl.Clear; 
           SQl.Add('select * from bomindex where name = :b'); 
            parameters.ParamByName('b').Value:=''+Edit1.Text+''; 
          open; 
          Edit; 
          FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit4.Text)-strtofloat(Edit3.Text)])); 
          updaterecord; 
          post; 
        end; 
    这里想实现00001 总宽数123cm要减去每次切的宽度20cm,最后得到123-20*3=63,这才是正确的
    但这里只实现了123-20*1,只实现了一次,没有切三次with Adoquery4 do 
        begin 
          Close; 
          SQl.Clear; 
           SQl.Add('select * from bomindex where name = :b'); 
            parameters.ParamByName('b').Value:=''+Edit1.Text+''; 
          open; 
          Edit; 
          FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit4.Text)-strtofloat(Edit3.Text)]));  
          updaterecord; 
          post; 
        end; 
    清楚了吧
      

  2.   

     with Adoquery4 do  
        begin  
          Close;  
          SQl.Clear;  
           SQl.Add('select * from bomindex where name = :b');  
            //parameters.ParamByName('b').Value:=''+Edit1.Text+'';  
            parameters.ParamByName('b').Value:=Edit1.Text; //!!改一下试试           
          open;  
          Edit;  
          FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit4.Text)-strtofloat(Edit3.Text)]));  
          updaterecord;  
          post;  
        end;  
      

  3.   

    var 
      a,b:integer; 
      Width: Double;//!!
    begin
    Width := strtofloat(Edit4.Text); //!!
    For a:=1 to StrToInt(Edit2.Text) do 
    begin 
     with Adoquery2 do   //保存主表信息 
        begin 
          Close; 
          SQl.Clear; 
          SQl.Add('select * from fj'); 
          open; 
          insert; 
          FieldByName('fj').AsString:=edit1.Text+'0'+IntToStr(a); 
          FieldByName('kd').AsString:=edit3.Text; 
          post; 
        end; 
            with Adoquery4 do 
        begin 
          Close; 
          SQl.Clear; 
           SQl.Add('select * from bomindex where name = :b'); 
            parameters.ParamByName('b').Value:=''+Edit1.Text+''; 
          open; 
          Edit; 
          Width := Width  - strtofloat(Edit3.Text);//每更减一点
          //strtofloat(Edit3.Text)])); 
          FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit4.Text)-strtofloat(Edit3.Text)]));  //这里有问题
           FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[Width]));  
          updaterecord; 
          post; 
        end; 
    end; 
    end; 
      

  4.   

    其实我认为,你没有必要分一次就减一次,还不如分了以后再一次计算余下部分保存,这样速度快呀!谢谢你,我实现成功了
      begin
      inherited;
      if strtofloat(Edit4.Text)<strtofloat(Edit2.Text) * strtofloat(Edit3.Text) then
      begin
        Application.MessageBox('分卷宽度大于实现宽度','提示',mb_ok);
        Exit;
      end;  begin
       try
        dm1.ADOConnection1.BeginTrans;  //启动事务
    For a:=1 to StrToInt(Edit2.Text) do
    begin
     with Adoquery2 do   //保存主表信息
        begin
          Close;
          SQl.Clear;
          SQl.Add('select * from fj');
          open;
          insert;
          FieldByName('fj').AsString:=edit1.Text+'0'+IntToStr(a);
          FieldByName('kd').AsString:=edit3.Text;
          FieldByName('name').AsString:=edit1.Text;
          post;
        end;
            with Adoquery4 do
       begin
          Close;
          SQl.Clear;
           SQl.Add('select * from bomindex where name = :b');
            parameters.ParamByName('b').Value:=''+Edit1.Text+'';
          open;
          Edit;
          FieldByName('kd').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit4.Text)-strtofloat(Edit2.Text)*strtofloat(Edit3.Text)]));
          updaterecord;
          post;
        end;end;
     dm1.ADOConnection1.CommitTrans;      //提交事务
        Application.MessageBox('分卷成功','提示',mb_ok);  except
        dm1.ADOConnection1.RollbackTrans;      //回滚事务
        Application.MessageBox('分卷不成功','提示',mb_ok);
      end;
    不过我还想得到相应的分切明细表,如图编号为00001的卷,下面还有三个小卷,当切三次时,应该得到9小卷,
    也就是还想得到
    小卷编号    大卷编号
    p0000101  0000101
    p0000102  0000101
    p0000103  0000101
    p0000101  0000102
    p0000102  0000102
    p0000103  0000102
    p0000101  0000103
    p0000102  0000103
    p0000103  0000103
    我不知道如何循环取得小卷编号,并与切卷数关联产生
    这是输入大卷号得到相应小卷的代码
    with adoquery1 do
      begin
        close;
        SQl.Clear;
           SQl.Add('select * from bomdetail where name = :a');
          parameters.ParamByName('a').Value:=''+Edit1.Text+'';
        Open;
      end;希望你再帮我一次,万分感激