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

📄 upedit.~pas

📁 不完备信息的数据发现
💻 ~PAS
字号:
unit upedit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, DB, ADODB, Buttons, Grids, DBGrids;
type
  TDataVar = array of string;

type
  Tupeditf = class(TForm)
    SB_save: TSpeedButton;
    DS_productinfo: TDataSource;
    Q_productinfo: TADOQuery;
    DBEdit_cpbh: TDBEdit;
    Label1: TLabel;
    DBEdit_price: TDBEdit;
    DBEdit_size: TDBEdit;
    DBEdit_maxspeed: TDBEdit;
    DBEdit_decision: TDBEdit;
    DBEdit_mileage: TDBEdit;
    Q_price: TADOQuery;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Q_size: TADOQuery;
    Q_speed: TADOQuery;
    jc: TSpeedButton;
    Q_all: TADOQuery;
    DB_jc: TDBGrid;
    DS_jc: TDataSource;
    Q_all2: TADOQuery;
    Q_temp: TADOQuery;
    Q_all3: TADOQuery;
    SpeedButton1: TSpeedButton;
   procedure SB_saveClick(Sender: TObject);
   procedure FormShow(Sender: TObject);
   procedure jcClick(Sender: TObject);
   procedure SpeedButton1Click(Sender: TObject);
     private
    { Private declarations }
  public
   function getdecision:TDataVar;
   function gyjc(decision:TDataVar):TDataVar;
   function check(name,str1,str2:string):bool;
   procedure jcgz(name:string;decisionexx,DataVar_name:TDataVar);
    { Public declarations }
  end;

var
  upeditf: Tupeditf;
  DataVar_decision,DataVar_decisionex,DataVar_decisionexx:TDataVar;
  i:integer;
  j,m,k:integer;
implementation

uses dm, main_page, upper;
{$R *.dfm}


procedure Tupeditf.SB_saveClick(Sender: TObject);
var descision:string;
    hprice,lprice,hsize,lsize,hspeed,lspeed:double;
begin
  Q_price.Close;
  Q_price.SQL.Text:='select * FROM '+DatabaseName+'priceset' ;
  Q_price.Open;
  hprice:=Q_price.FieldByName('hprice').asfloat;
  lprice:=Q_price.FieldByName('lprice').asfloat;
  Q_size.Close;
  Q_size.SQL.Text:='select * FROM '+DatabaseName+'sizeset' ;
  Q_size.Open;
  hsize:=Q_size.FieldByName('hsize').asfloat;
  lsize:=Q_size.FieldByName('lsize').asfloat;
  Q_speed.Close;
  Q_speed.SQL.Text:='select * FROM '+DatabaseName+'speedset' ;
  Q_speed.Open;
  hspeed:=Q_speed.FieldByName('hspeed').asfloat;
  lspeed:=Q_speed.FieldByName('lspeed').asfloat;
  if  DBEdit_price.Text<>'' then
  begin
    if  strtofloat(DBEdit_price.Text)>=hprice then
     Q_productinfo.FieldByName('price').asstring:='high'
    else  if strtofloat(DBEdit_price.Text)<lprice then
     Q_productinfo.FieldByName('price').asstring:='low';
   end
  else
   Q_productinfo.FieldByName('price').asstring:='*';

  if  DBEdit_size.Text<>'' then
  begin
    if  strtofloat(DBEdit_size.Text)>=hprice then
     Q_productinfo.FieldByName('size').asstring:='full'
    else  if strtofloat(DBEdit_size.Text)<lprice then
     Q_productinfo.FieldByName('size').asstring:='compact';
   end
  else
   Q_productinfo.FieldByName('size').asstring:='*';

  if  DBEdit_maxspeed.Text<>'' then
  begin
    if  strtofloat(DBEdit_maxspeed.Text)>=hspeed then
     Q_productinfo.FieldByName('Max_speed').asstring:='high'
    else  if strtofloat(DBEdit_maxspeed.Text)<lspeed then
     Q_productinfo.FieldByName('Max_speed').asstring:='low';
   end
  else
   Q_productinfo.FieldByName('Max_speed').asstring:='*';

   Q_productinfo.CheckBrowseMode;
   Q_productinfo.ExecSQL;
   upf.Q_product.close;
   upf.Q_product.open;
   upf.Q_product.Locate('product_no',Q_productinfo.FieldByName('product_no').asstring,[]);

end;

procedure Tupeditf.FormShow(Sender: TObject);
begin
   if ISinsert=true then
   begin
    Q_productinfo.Close;
    Q_productinfo.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where 1<>1';
    Q_productinfo.Open;
    Q_productinfo.Insert;
    end
  else
   begin
    Q_productinfo.Close;
    Q_productinfo.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where product_no ='''+upf.Q_product.fieldbyname('product_no').asstring+'''';
    Q_productinfo.Open;
    Q_productinfo.edit;
   end;
end;

function Tupeditf.getdecision:TDataVar;
var good,poor,excel:string;
    decision:TDataVar;
begin
  Q_all.Close;
  Q_all.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where decision_ex=''good''';
  Q_all.Open;
  Q_all.First;
  good:='';
  while not Q_all.Eof do
  begin
  good:=good+Q_all.FieldByName('product_no').asstring;
  Q_all.Next;
  end;

  Q_all.Close;
  Q_all.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where decision_ex=''poor''';
  Q_all.Open;
  Q_all.First;
  poor:='';
  while not Q_all.Eof do
  begin
  poor:=poor+Q_all.FieldByName('product_no').asstring;
  Q_all.Next;
  end;

  Q_all.Close;
  Q_all.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where decision_ex=''good,excel''';
  Q_all.Open;
  Q_all.First;
  excel:='';
  while not Q_all.Eof do
  begin
  excel:=excel+Q_all.FieldByName('product_no').asstring;
  Q_all.Next;
  end;
  SetLength(decision, 3);
  decision[0] := good;
  decision[1] := poor;
  decision[2] := excel;
  result:=decision;
end;

function Tupeditf.gyjc(decision:TDataVar):TDataVar;
var p,t,l,m: integer ;
    str:string;
    decisionex,decisionexx:TDataVar;
begin
  SetLength(decisionex, 0);
  for i := 0 to 5 do
  begin
    SetLength(decisionex, 6);
    lenth := Length(DataVar[i]);
    if lenth > 0 then
    begin
      for t := 1 to lenth do
      begin
        str_temp := Copy(DataVar[i], t, 1);
        for p:=0 to 2 do
        begin
        wz := dmf.PosEx(str_temp, decision[p]);
        if wz <> 0 then
         begin
           m:=0;
           for l:=1 to length(decisionex[i]) do
           begin
             str:=Copy(decisionex[i],l,1);
             if IntToStr(p)<> str then m:=m+1;
           end;
            if m=length(decisionex[i])
            then decisionex[i] := decisionex[i] +IntToStr(p);
         end;
      end;
    end;
  end;
 end;
   SetLength(decisionexx,0);
   SetLength(decisionexx,4);
   for i:=0 to 5 do
   begin
   if decisionex[i]='0' then
   decisionexx[0] := decisionexx[0] +IntToStr(i+1);
   if decisionex[i]='1' then
   decisionexx[1] := decisionexx[1] +IntToStr(i+1);
   if decisionex[i]='02' then
   decisionexx[2] := decisionexx[2] +IntToStr(i+1);
   if decisionex[i]='2' then
   decisionexx[3] := decisionexx[3] +IntToStr(i+1);
   end;
 result:=decisionexx;
end;




procedure Tupeditf.jcClick(Sender: TObject);
var  size1,size2,maxspeed1,maxspeed2: string;
  DataVar_size,DataVar_maxspeed: TDataVar;
    size,decision:string;
begin

  SetLength(DataVar_size, 2);
  SetLength(DataVar_maxspeed,2);
  Q_all.Close;
  Q_all.SQL.Text:=' select product_no FROM '+DatabaseName+' decision where size<>''full''' ;
  Q_all.Open;
  Q_all.First;
  while not Q_all.eof do  //取六组数据
  if  Q_all.FieldByName('product_no').AsInteger<7  then
  begin
   size1:=size1+Q_all.FieldByName('product_no').asstring;
   Q_all.Next;
  end;
  Q_all.Close;
  Q_all.SQL.Text:='select product_no FROM '+DatabaseName+'decision where size<>''compact''' ;
  Q_all.Open;
  Q_all.First;
  while not Q_all.eof do  //取六组数据
  if  Q_all.FieldByName('product_no').AsInteger<7  then
  begin
   size2:=size2+Q_all.FieldByName('product_no').asstring;
   Q_all.Next;
  end;
  DataVar_size[0] := size1;
  DataVar_size[1] := size2;


  Q_all.Close;
  Q_all.SQL.Text:=' select product_no FROM '+DatabaseName+' decision where Max_speed<>''low''' ;
  Q_all.Open;
  Q_all.First;
  while not Q_all.eof do  //取六组数据
  if  Q_all.FieldByName('product_no').AsInteger<7  then
  begin
   maxspeed1:=maxspeed1+Q_all.FieldByName('product_no').asstring;
   Q_all.Next;
  end;
  Q_all.Close;
  Q_all.SQL.Text:='select product_no FROM '+DatabaseName+'decision where Max_speed<>''high''' ;
  Q_all.Open;
  Q_all.First;
  while not Q_all.eof do  //取六组数据
  if  Q_all.FieldByName('product_no').AsInteger<7  then
  begin
   maxspeed2:=maxspeed2+Q_all.FieldByName('product_no').asstring;
   Q_all.Next;
  end;
  DataVar_maxspeed[0] := maxspeed1;
  DataVar_maxspeed[1] := maxspeed2;
  DataVar_decision:=getdecision;
  DataVar_decisionexx:=gyjc(DataVar_decision);
   jcgz('size',DataVar_decisionexx,DataVar_size);
   jcgz('Max_speed',DataVar_decisionexx,DataVar_maxspeed);
   Q_all2.Close;
   Q_all2.SQL.Text:=' select *  FROM '+DatabaseName+'decisionex ';
   Q_all2.Open;

end;

function Tupeditf.check(name,str1,str2:string):bool;
var dec:string;
begin
  Q_temp.Close;
  Q_temp.SQL.Text:=' select *  FROM '+DatabaseName+'decisionex where '+name+'='''+str1+'''';
  Q_temp.Open;
  if Q_temp.IsEmpty  then   result:=true
  else
  begin
    dec:=Q_temp.FieldByName('decision').asstring;
    if str2<>dec then
    begin
     Q_all3.Close;
     Q_all3.SQL.Text:=' select *  FROM '+DatabaseName+'decisionex where '+name+'='''+str1+'''';
     Q_all3.Open;
     Q_all3.Edit;
     Q_all3.Delete;
     Q_all3.CheckBrowseMode;
     Q_all3.ExecSQL;
    end;
    result:=false;
  end;
end;

procedure Tupeditf.jcgz(name:string;decisionexx,DataVar_name:TDataVar);
begin
   Q_all2.Close;
   Q_all2.SQL.Text:=' select '+ name+',decision  FROM '+DatabaseName+'decisionex where 1<>1';
   Q_all2.Open;
   for j := 0 to 2 do
   begin
    m := 0;
    lenth := Length(decisionexx[j]);
    if lenth > 0 then
    begin
      for i := 1 to lenth do
      begin
        for k:=0 to 1 do
        begin
        str_temp := Copy(decisionexx[j], i, 1);
        wz := dmf.PosEx(str_temp, DataVar_name[k]);
        if wz <> 0 then m := m + 1;
      end;
      if m = lenth then
      begin
          if j=0  then
        begin
             Q_all.Close;
              Q_all.SQL.Text:='select '+ name+',decision  FROM '+DatabaseName+'decision where decision=''good''';
              Q_all.Open;
              Q_all.First;
              while not Q_all.Eof do
              begin
               if check(name,Q_all.FieldByName(name).asstring,Q_all.FieldByName('decision').asstring) then
               begin
                Q_all2.Insert;
                Q_all2.FieldByName(name).asstring:=Q_all.FieldByName(name).asstring;
                Q_all2.FieldByName('decision').asstring:=Q_all.FieldByName('decision').asstring;
                Q_all2.CheckBrowseMode;
                Q_all2.ExecSQL;
               end;
               Q_all.Next;
              end;
        end;
          if j=1  then
        begin
              Q_all.Close;
              Q_all.SQL.Text:='select '+ name+',decision  FROM '+DatabaseName+'decision where decision=''poor''';
              Q_all.Open;
              while not Q_all.Eof do
              begin
                if check(name,Q_all.FieldByName(name).asstring,Q_all.FieldByName('decision').asstring) then
               begin
                Q_all2.Insert;
                Q_all2.FieldByName(name).asstring:=Q_all.FieldByName(name).asstring;
                Q_all2.FieldByName('decision').asstring:=Q_all.FieldByName('decision').asstring;
                Q_all2.CheckBrowseMode;
                Q_all2.ExecSQL;
               end;
               Q_all.Next;
              end;
        end;
       end;

      end;
    end;
  end;

end;

procedure Tupeditf.SpeedButton1Click(Sender: TObject);
begin


 if  Q_productinfo.FieldByName('size').asstring='full'
 then
  begin
   DBEdit_decision.Text:='good';
   Q_productinfo.edit;
   Q_productinfo.FieldByName('decision').asstring:='good';
   Q_productinfo.CheckBrowseMode;
   Q_productinfo.ExecSQL;
   upf.Q_product.close;      //刷新
   upf.Q_product.open;
   upf.Q_product.Locate('product_no',Q_productinfo.FieldByName('product_no').asstring,[]);
  end;
end;

end.






⌨️ 快捷键说明

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