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

📄 dinsert.~pas

📁 有关delphi的应用
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
unit dinsert;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls, DB, ADODB, DBGrids;

type
  Tfrminsert = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    GroupBox3: TGroupBox;
    snEdit: TEdit;
    Label3: TLabel;
    GroupBox4: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    prodorderCBox: TComboBox;
    pnCBox: TComboBox;
    GroupBox5: TGroupBox;
    GroupBox6: TGroupBox;
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    ADODataSet1: TADODataSet;
    ADODataSet2: TADODataSet;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Label4: TLabel;
    JobOrderEdit: TEdit;
    Button2: TButton;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure pnCBoxChange(Sender: TObject);
  private
    { Private declarations }
    count1,count2:integer;
  public
    { Public declarations }
  end;

var
  frminsert: Tfrminsert;

implementation

uses datalink, change1, change2;

{$R *.dfm}

procedure Tfrminsert.FormShow(Sender: TObject);
var str:string;
begin
dbgrid1.Columns[2].Color:=clcream;
dbgrid2.Columns[5].Color:=clcream;
 with DM do
    begin
      with adoquery1 do
      begin
        close;
        with sql do
        begin
        clear;
        add('select distinct pn from device_paraset1 union select distinct pn from device_paraset2');
        end;
        open;
      end;
    end;
  DM.ADOQuery1.First;
  while not DM.ADOQuery1.Eof do
  begin
    pnCBox.Items.Add(DM.ADOQuery1.FieldValues['pn']);
    DM.ADOQuery1.Next;
  end;
  pnCBox.ItemIndex:=0;
  str:='select distinct prodorder from device_paraset1 where pn='''+pnCBox.Text+''' union select distinct prodorder from device_paraset2 where pn='''+pnCBox.Text+''' ';
   with DM do
    begin
      with adoquery2 do
      begin
        close;
        with sql do
        begin
        clear;
        add(str);
        //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;
  stringgrid1.Cells[0,0]:='参数说明';
  stringgrid1.Cells[1,0]:='测试值';
  stringgrid2.Cells[0,0]:='参数说明';
  stringgrid2.Cells[1,0]:='温度';
  stringgrid2.Cells[2,0]:='参数上限值';
  stringgrid2.Cells[3,0]:='参数下限值';
  stringgrid2.Cells[4,0]:='测试数据';
  stringgrid1.ColWidths[0]:=100;
  stringgrid2.ColWidths[0]:=150;
end;

procedure Tfrminsert.Button1Click(Sender: TObject);
var
str:string;
begin
 str:='select paraname from device_paraset1 where (prodorder='''+prodorderCBox.Text+''')and(pn='''+pnCBox.Text+''')';
 with DM do
  begin
    with adoquery1 do
    begin
      close;
      with sql do
      begin
      clear;
      add(str);
      end;
      open;
    end;
  end;
 count1:=1;
 dm.ADOQuery1.First;
 while not dm.ADOQuery1.Eof do
 begin
   stringgrid1.Cells[0,count1]:=dm.ADOQuery1.FieldValues['paraname'];
   stringgrid1.Cells[1,count1]:='';
   count1:=count1+1;
   dm.ADOQuery1.Next;
 end;
 stringgrid1.RowCount:=count1;


  str:='select paraname,temperature,maxvalue,minvalue from device_paraset2 where (prodorder='''+prodorderCBox.Text+''')and(pn='''+pnCBox.Text+''') and(para_id2 not in (select para_id3 from device_para3cmp))';
 with DM do
  begin
    with adoquery1 do
    begin
      close;
      with sql do
      begin
      clear;
      add(str);
      end;
      open;
    end;
  end;
 count2:=1;
 dm.ADOQuery1.First;
 while not dm.ADOQuery1.Eof do
 begin
   stringgrid2.Cells[0,count2]:=dm.ADOQuery1.FieldValues['paraname'];
   stringgrid2.Cells[1,count2]:=dm.ADOQuery1.FieldValues['temperature'];
   stringgrid2.Cells[2,count2]:=dm.ADOQuery1.FieldValues['maxvalue'];
   stringgrid2.Cells[3,count2]:=dm.ADOQuery1.FieldValues['minvalue'];
   stringgrid2.Cells[4,count2]:='';
   count2:=count2+1;
   dm.ADOQuery1.Next;
 end;
if count2=1 then
begin
 stringgrid2.RowCount:=count2+1;
 stringgrid2.Cells[0,1]:='';
 stringgrid2.Cells[1,1]:='';
 stringgrid2.Cells[2,1]:='';
 stringgrid2.Cells[3,1]:='';
 stringgrid2.Cells[4,1]:='';
 end
else
 stringgrid2.RowCount:=count2;
 adodataset1.Active:=false;
 adodataset1.CommandText:='select v.value_id1, s.paraname, v.testvalue, v.sn, v.joborder from device_testvalue1 v,device_paraset1 s where (s.para_id1=v.para_id1)and(s.prodorder='''+prodorderCBox.Text+''')and(s.pn='''+pnCBox.Text+''')';
 adodataset1.Active:=true;
 adodataset2.Active:=false;
 adodataset2.CommandText:='select v.value_id2, s.paraname, s.temperature, s.maxvalue, s.minvalue, v.testvalue, v.sn, v.joborder, v.status from device_testvalue2 v,device_paraset2 s where (s.para_id2=v.para_id2)and(s.prodorder='''+prodorderCBox.Text+''')and(s.pn='''+pnCBox.Text+''')';
 adodataset2.Active:=true;
end;

procedure Tfrminsert.Button2Click(Sender: TObject);
   procedure JudgeStatusInsert(i:integer;j:integer);
   var str2,status:string;
   begin
     if (strtofloat(stringgrid2.Cells[2,i])<strtofloat(stringgrid2.Cells[4,j])) or (strtofloat(stringgrid2.Cells[3,i])>strtofloat(stringgrid2.Cells[4,j])) then
        status:='fail'
     else
       status:='pass';
     str2:='insert into device_testvalue2(para_id2,sn,joborder,testvalue,status,indate) values('''+inttostr(dm.ADOQuery1.FieldValues['para_id2'])+''','''+snedit.Text+''','''+joborderedit.Text+''','''+stringgrid2.Cells[4,j]+''','''+status+''','''+formatdatetime('yyyy-mm-dd',date)+''')';
     with DM do
     begin
         with adoquery2 do
         begin
           close;
           with sql do
           begin
             clear;
             add(str2);
           end;
           execsql;
         end;
       end;
    end;
var
  str1, str2 : string;
  i , j : integer;
  Garben:boolean;
  max, min : real;
  temp:real;
  status:string;
begin
  if JobOrderEdit.Text='' then
  begin
    application.MessageBox('JobOrder不能为空','提示信息',mb_ok);
    JobOrderEdit.SetFocus;
    exit;
  end;
  if snEdit.Text='' then
  begin
    application.MessageBox('SN不能为空','提示信息',mb_ok);
    snEdit.SetFocus;
    exit;
  end;
  //光开关模块判断是否重号
  if pnCBox.Text='1CW-057000-06A' then
  begin
    dm.ADOQuery2.Close;
    dm.ADOQuery2.SQL.Clear;
    dm.ADOQuery2.SQL.Add('select testvalue from device_testvalue1 where (para_id1='''+'1127'+''')and(testvalue='''+stringgrid1.Cells[1,3]+''')');
    dm.ADOQuery2.Open;
    if dm.ADOQuery2.RecordCount>0 then
    begin
      showmessage('光开关SN重号');
      exit;
    end;

  end;
  //判断该数据是否已经录入
      str2:='select value_id2 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;
          open;
        end;
        with adoquery1 do
        begin
          str2:='select value_id1 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;
          open;
        end;
      if (adoquery1.RecordCount>0) or (adoquery2.RecordCount>0) then
      begin
        showmessage('数据库里已有该项sn的数据,请检测后输入,或删除该项信息后再输入');
        snedit.SetFocus;
        exit;
      end;
      end;
  try

⌨️ 快捷键说明

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