⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dinsert.~pas

📁 有关delphi的应用
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
    //保存stringgrid1的数据
    for j:=1 to count1-1 do
    begin
      str1:='select para_id1 from device_paraset1 where (paraname='''+stringgrid1.Cells[0,j]+''')and(prodorder='''+prodorderCBox.Text+''')and(pn='''+pnCBox.Text+''')';
      with DM do
      begin
        with adoquery1 do
        begin
          close;
          with sql do
          begin
            clear;
            add(str1);
          end;
          open;
        end;
      end;
      str1:='insert into device_testvalue1(para_id1,sn,joborder,testvalue,indate) values('''+inttostr(dm.ADOQuery1.FieldValues['para_id1'])+''','''+snedit.Text+''','''+joborderedit.Text+''','''+stringgrid1.Cells[1,j]+''','''+formatdatetime('yyyy-mm-dd',date)+''')';
      with DM do
      begin
        with adoquery2 do
        begin
          close;
          with sql do
          begin
            clear;
            add(str1);
          end;
          execsql;
        end;
      end;
    end;


    //保存stringgrid2的数据
    for j:=1 to count2-1 do
    begin
      Garben:=false;
      //取序号
      str2:='select para_id2,temperature,maxvalue,minvalue from device_paraset2 where (paraname='''+stringgrid2.Cells[0,j]+''')and(prodorder='''+prodorderCBox.Text+''')and(pn='''+pnCBox.Text+''')and(temperature='''+stringgrid2.Cells[1,j]+''')';
      with DM do
      begin
        with adoquery1 do
        begin
          close;
          with sql do
          begin
            clear;
            add(str2);
          end;
          open;
        end;
      end;
      //判断该参数的温度是否为25
      if  stringgrid2.Cells[1,j]='25' then//察看该参数是否有对应的75,0度值及对应值是否为'#'
      begin

        for i:=1 to count2-1 do
        begin
          if (i<>j)and(stringgrid2.Cells[0,i]=stringgrid2.Cells[0,j]) then
          begin
            if stringgrid2.Cells[4,i]<>'#' then
            begin
              Garben:=true;
              break;
            end;
          end;
        end;

        if Garben=true then//查找相同参数不同温度下的参数缩设定的范围,判断pass fail
          JudgeStatusInsert(i,j)

        else//常规判断
          JudgeStatusInsert(j,j);
      end
      else//不为25,判断数值是否为'#',若为'#',直接添加pass数据,若不为'#',常规判断
      begin
        if stringgrid2.Cells[4,j]='#' then
        begin
          str2:='insert into device_testvalue2(para_id2,sn,joborder,testvalue,status,indate) values('''+inttostr(dm.ADOQuery1.FieldValues['para_id2'])+''','''+snedit.Text+''','''+joborderedit.Text+''','''+'#'+''','''+'pass'+''','''+formatdatetime('yyyy-mm-dd',date)+''')';
          dm.ADOQuery2.Close;
          dm.ADOQuery2.SQL.Clear;
          dm.ADOQuery2.SQL.Add(str2);
          dm.ADOQuery2.ExecSQL;
        end
        else
        begin
          JudgeStatusInsert(j,j);
        end;
      end;
    end;

    //保存有比较值的数据
    dm.ADOQuery2.Close;
    dm.ADOQuery2.SQL.Clear;
    dm.ADOQuery2.SQL.Add('select distinct p.para_id2,p.maxvalue,p.minvalue,c.method from device_paraset2 p,device_para3cmp c where (p.pn='''+PNCBox.Text+''')and(p.prodorder='''+prodorderCBox.Text+''')and(c.para_id3=p.para_id2)');
    dm.ADOQuery2.Open;
    if  dm.ADOQuery2.RecordCount>0 then
    begin
      dm.ADOQuery2.First;
      while not dm.ADOQuery2.Eof do
      begin
        dm.ADOQuery1.Close;
        dm.ADOQuery1.SQL.Clear;
        dm.ADOQuery1.SQL.Add('select para_id2,testvalue from device_testvalue2 where para_id2 in (select para_idcmp from device_para3cmp where para_id3='''+dm.ADOQuery2.FieldByName('para_id2').AsString+''')AND(p.pn='''+PNCBox.Text+''')and(p.prodorder='''+prodorderCBox.Text+''') ');
        dm.ADOQuery1.Open;
        dm.ADOQuery1.First;
        max:=dm.ADOQuery1.FieldByName('testvalue').AsFloat;
        min:=dm.ADOQuery1.FieldByName('testvalue').AsFloat;
        while not dm.ADOQuery1.Eof do
        begin
          temp:=dm.ADOQuery1.FieldByName('testvalue').AsFloat;
          if temp>max then
            max:=temp;
          if temp<min then
            min:=temp;
          dm.ADOQuery1.Next;
        end;

         //插入数据
        if dm.ADOQuery2.FieldByName('method').AsString='sub' then
        begin
          temp:=max-min;
        end
        else if dm.ADOQuery2.FieldByName('method').AsString='max' then
        begin
          temp:=max;
        end
        else if dm.ADOQuery2.FieldByName('method').AsString='min' then
        begin
          temp:=min;
        end;

        if (temp<=dm.ADOQuery2.FieldByName('maxvalue').AsFloat)and(temp>=dm.ADOQuery2.FieldByName('minvalue').AsFloat) then
          status:='pass'
        else
          status:='fail';
        str2:='insert into device_testvalue2(para_id2,sn,joborder,testvalue,status,indate) values('''+inttostr(dm.ADOQuery2.FieldValues['para_id2'])+''','''+snedit.Text+''','''+joborderedit.Text+''','''+floattostr(temp)+''','''+status+''','''+formatdatetime('yyyy-mm-dd',date)+''')';         dm.ADOQuery1.Close;
        dm.ADOQuery1.SQL.Clear;
        dm.ADOQuery1.SQL.Add(str2);
        dm.ADOQuery1.ExecSQL;
 
        dm.ADOQuery2.Next;
      end;
    end;

    Application.MessageBox('数据保存成功','提示信息',mb_ok);
    adodataset1.Active:=false;
    adodataset1.Active:=true;
    adodataset1.Last;
    adodataset2.Active:=false;
    adodataset2.Active:=true;
    adodataset1.Last;
    snedit.SetFocus;
   except
      str2:='delete from device_testvalue2 where (sn='''+snedit.Text+''')and(joborder='''+joborderedit.Text+''')and(para_id2 in (select para_id2 from device_paraset2 where prodorder='''+prodorderCBox.Text+'''))';
      with DM do
      begin
        with adoquery2 do
        begin
          close;
          with sql do
          begin
            clear;
            add(str2);
          end;
          execsql;

          str2:='delete from device_testvalue1 where (sn='''+snedit.Text+''')and(joborder='''+joborderedit.Text+''')and(para_id1 in (select para_id1 from device_paraset1 where prodorder='''+prodorderCBox.Text+'''))';
          close;
          with sql do
          begin
            clear;
            add(str2);
          end;
          execsql;
        end;
      end;
      showmessage('插入数据有误,请监测后再做插入');
   end;
end;

procedure Tfrminsert.FormClose(Sender: TObject; var Action: TCloseAction);
begin
pnCBox.Items.Clear;
prodorderCBox.Items.Clear;
end;

procedure Tfrminsert.Button3Click(Sender: TObject);
begin
  Application.CreateForm(Tfrmchange1, frmchange1);
 frmchange1.ShowModal;
end;

procedure Tfrminsert.Button5Click(Sender: TObject);
begin
  Application.CreateForm(Tfrmchange2, frmchange2);
  frmchange2.ShowModal;
end;

procedure Tfrminsert.Button4Click(Sender: TObject);
var str,str1:string;
begin
  if windows.MessageBox(0,'即将删除此项信息!确定要删除所选的记录?','提示信息',MB_YESNO+MB_DEFBUTTON2)=IDNO then
    exit
  else
  begin
  str:=inttostr(DBGrid1.Fields[0].Value);
  str1:='delete from device_testvalue1 where value_id1='''+str+'''';
  with dm do
    begin
      with adoquery1 do
      begin
          Close;
          with SQL do
           begin
            Clear;
            add(str1);
           end;
           ExecSQL;
      end;
    end;
  end;
  adodataset1.Active:=false;
  adodataset1.Active:=true;
end;

procedure Tfrminsert.Button6Click(Sender: TObject);
var str,str1:string;
begin
  if windows.MessageBox(0,'即将删除此项信息!确定要删除所选的记录?','提示信息',MB_YESNO+MB_DEFBUTTON2)=IDNO then
    exit
  else
  begin
  str:=inttostr(DBGrid2.Fields[0].Value);
  str1:='delete from device_testvalue2 where value_id2='''+str+'''';
  with dm do
    begin
      with adoquery1 do
      begin
          Close;
          with SQL do
           begin
            Clear;
            add(str1);
           end;
           ExecSQL;
      end;
    end;
  end;
  adodataset2.Active:=false;
  adodataset2.Active:=true;
end;


procedure Tfrminsert.pnCBoxChange(Sender: TObject);
var str:string;
begin
str:='select distinct prodorder,ordernum from device_paraset1 where pn='''+pnCBox.Text+''' order by ordernum';
prodorderCBox.Items.Clear;
   with DM do
    begin
      with adoquery2 do
      begin
        close;
        with sql do
        begin
        clear;
        add(str);
//        add('select distinct prodorder from device_paraset1 where pn=:pn union select distinct prodorder from device_paraset2 where pn=:pn');
        //union select distinct prodorder from device_paraset2
        end;
//        Parameters.ParamByName('pn').Value:=pnCBox.Text;
        open;
      end;
    end;
  DM.ADOQuery2.First;
  while not DM.ADOQuery2.Eof do
  begin
    prodorderCBox.Items.Add(DM.ADOQuery2.FieldValues['prodorder']);
    DM.ADOQuery2.Next;
  end;
  prodorderCBox.ItemIndex:=0;
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -