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

📄 upper.~pas

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

interface

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

type
  TDataVar = array of string;

type
  Tupf = class(TForm)
    Q_productinfo: TADOQuery;
    DS_productinfo: TDataSource;
    Q_product: TADOQuery;
    DBGrid1: TDBGrid;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    gua1: TMenuItem;
    Q_all: TADOQuery;
    N5: TMenuItem;
    procedure FormCreate(Sender: TObject);
    function compact(l: integer): TDataVar;
    function compact1: TDataVar;
    procedure ResetValue(col: integer);
    function PosEx(const SubStr, S: string): integer;
    function bj(DataVarcom1,DataVarcom2:TDataVar):bool;
    procedure DBGrid1DblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure gua1Click(Sender: TObject);
  private
    { Private declarations }
     function getdecision:TDataVar;
     function gyjc(decision:TDataVar):TDataVar;
  public

    { Public declarations }
  end;

var
  upf:Tupf;
  a: array[0..5, 0..4] of string;
  i, j, k: integer;
  DataVar: TDataVar;
  DataVar1: TDataVar;
  DataVar2: TDataVar;
  DataVar3: TDataVar;
  DataVar4: TDataVar;
 // DataVar_goodex,DataVar_Poorex,DataVar_Excelex,DataVar_good1ex,DataVar_Poor1ex,DataVar_Excel1ex: TDataVar;
  str, str_temp: string;
  wz, lenth, m: integer;
  //DataVar_good, DataVar_Poor, DataVar_Excel, DataVar_good1, DataVar_Poor1, DataVar_Excel1,DataVar_decisionex: TDataVar;
  decnexx:TDataVar;
implementation

{$R *.dfm}
uses dm, lproductex, upedit;
procedure Tupf.FormCreate(Sender: TObject);
var i:integer;
begin
 Q_productinfo.Close;
 Q_productinfo.SQL.Text:='select * FROM '+DatabaseName+'decision order by product_no';
 Q_productinfo.Open;
 Q_productinfo.First;
 i:=0;
 while not Q_productinfo.Eof do
 begin
  a[i][0]:=Q_productinfo.FieldByName('price').asstring;
  a[i][1]:=Q_productinfo.FieldByName('Mileage').asstring;
  a[i][2]:=Q_productinfo.FieldByName('size').asstring;
  a[i][3]:=Q_productinfo.FieldByName('Max_speed').asstring;
  a[i][4]:=Q_productinfo.FieldByName('decision').asstring;
  i:=i+1;
  if i=6 then break;
  Q_productinfo.Next;
 end;

  DataVar := compact1;
  DataVar1 := compact(0);
  DataVar2 := compact(1);
  DataVar3 := compact(2);
  DataVar4 := compact(3);

end;

function Tupf.compact(l: integer): TDataVar;
var DataVar_sat: TDataVar;
  bj: Boolean;
begin
  SetLength(DataVar_sat, 6);
  for k := 0 to 5 do
  begin
    for i := 0 to 5 do
    begin
      bj := True;
      for j := 0 to 3 do
      begin
        if j <> l then
        begin
          if ((a[k, j] <> a[i, j]) and (a[k, j] <> '*') and (a[i, j] <> '*')) then
          begin
            bj := false;
            break;
          end;
        end;
      end;
      if bj = True then
      begin
        DataVar_sat[k] := DataVar_sat[k] + (IntToStr(i + 1));
      end;
    end;
  end;
  Result := DataVar_sat;
end;

function Tupf.compact1: TDataVar;
var DataVar_sat: TDataVar;
  bj: Boolean;
begin
  SetLength(DataVar_sat, 6);
  for k := 0 to 5 do
  begin
    for i := 0 to 5 do
    begin
      bj := True;
      for j := 0 to 3 do
      begin
        if ((a[k, j] <> a[i, j]) and (a[k, j] <> '*') and (a[i, j] <> '*')) then
        begin
          bj := false;
          break;
        end;
      end;
      if bj = True then
      begin
        DataVar_sat[k] := DataVar_sat[k] + (IntToStr(i + 1));
      end;
    end;
  end;
  Result := DataVar_sat;
end;

procedure Tupf.ResetValue(col: integer);
begin
  a[0, col] := '*';
  a[1, col] := '*';
  a[2, col] := '*';
  a[3, col] := '*';
  a[4, col] := '*';
  a[5, col] := '*';
end;

function Tupf.PosEx(const SubStr, S: string): integer; //取出第一个已知字符的位置
var
  i, X: integer;
begin
  i := 1;
  while i <= Length(S) do
  begin
    if S[i] <> SubStr then Inc(i);
    if S[i] = SubStr then
    begin
      Result := i;
      exit;
    end;
  end;
end;
function Tupf.bj(DataVarcom1,DataVarcom2:TDataVar):bool;
var i,j:integer;
begin
  j:=0;
  for i:=0 to 5 do
  begin
    if DataVarcom1[i]=DataVarcom2[i]  then
    j:=j+1 else
    break;
  end;
  if  j=6 then result:=true
  else result:=false;
end;

procedure Tupf.DBGrid1DblClick(Sender: TObject);
begin
if not Q_product.IsEmpty then
   begin
    ISinsert:=false;
    upeditf:=Tupeditf.Create(nil);
    with upeditf do
     try
      ShowModal;
     finally
      free;
     end;
   end else
    begin
      MessageBox(Handle,'没有记录可修改!','提示信息', MB_ICONINFORMATION or MB_OK);
      exit;
    end;
end;

procedure Tupf.N1Click(Sender: TObject);
var i:integer;
begin
   Q_product.Close;
   Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct';
   Q_product.Open;
   if  not Q_product.IsEmpty then
   while  not Q_product.eof do
   begin
    Q_product.Delete;
    Q_product.ExecSQL;
   end;

   Q_product.Close;
   Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where 1<>1';
   Q_product.Open;
   Q_productinfo.First;
   i := 0;
   while not Q_productinfo.eof do
   begin
     Q_product.Insert;
      if bj(DataVar,DataVar1) then
     begin
       ResetValue(0);
       Q_product.FieldByName('price').asstring:='*';
     end else
       Q_product.FieldByName('price').asstring:=a[i][0];
       i := i+1;
       Q_product.FieldByName('product_no').asstring:=Q_productinfo.FieldByName('product_no').asstring;
       Q_product.CheckBrowseMode;
       Q_product.ExecSQL;
       Q_productinfo.Next;
   end;

   Q_product.Close;
   Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct order by product_no';
   Q_product.Open;
   Q_product.First;
   i := 0;
   while not Q_product.eof do
   begin
     Q_product.Edit;
     if bj(DataVar,DataVar2) then
     begin
       ResetValue(1);
       Q_product.FieldByName('mileage').asstring:='NULL';
     end else
       Q_product.FieldByName('mileage').asstring:=a[i][1];
    i := i+1;
    Q_product.CheckBrowseMode;
    Q_product.ExecSQL;
    Q_product.Next;
   end;

   Q_product.Close;
   Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct order by product_no';
   Q_product.Open;
   Q_product.First;
   i := 0;
   while not Q_product.eof do
   begin
     Q_product.Edit;
      if bj(DataVar,DataVar3) then
     begin
       ResetValue(2);
       Q_product.FieldByName('size').asstring:='*';
     end else
       Q_product.FieldByName('size').asstring:=a[i][2];
    i := i+1;
    Q_product.CheckBrowseMode;
    Q_product.ExecSQL;
    Q_product.Next;
   end;

   Q_product.Close;
   Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct order by product_no';
   Q_product.Open;
   Q_product.First;
   i := 0;
   while not Q_product.eof do
   begin
     Q_product.Edit;
     if bj(DataVar,DataVar4) then
     begin
       ResetValue(3);
       Q_product.FieldByName('max_speed').asstring:='*';
     end else
       Q_product.FieldByName('max_speed').asstring:=a[i][3];
    i := i+1;
    Q_product.CheckBrowseMode;
    Q_product.ExecSQL;
    Q_product.Next;
   end;
   Q_product.Close;
   Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct order by product_no';
   Q_product.Open;
   Q_product.First;
   i := 0;
   while not Q_product.eof do
   begin
     Q_product.Edit;
     if DataVar = DataVar4 then
     begin
       ResetValue(3);
       Q_product.FieldByName('decision').asstring:='*';
     end else
       Q_product.FieldByName('decision').asstring:=a[i][4];
    i := i+1;
    Q_product.CheckBrowseMode;
    Q_product.ExecSQL;
    Q_product.Next;
   end;
end;

procedure Tupf.N2Click(Sender: TObject);
begin
  ISinsert:=true;
  upeditf:=Tupeditf.Create(nil);
  with upeditf do
   try
    ShowModal;
   finally
    free;
   end;
end;

procedure Tupf.N3Click(Sender: TObject);
begin
  Q_product.Delete;
  Q_product.ExecSQL;
end;

procedure Tupf.N4Click(Sender: TObject);
begin
   if not Q_product.IsEmpty then
   begin
    ISinsert:=false;
    upeditf:=Tupeditf.Create(nil);
    with upeditf do
     try
      ShowModal;
     finally
      free;
     end;
   end else
    begin
      MessageBox(Handle,'没有记录可修改!','提示信息', MB_ICONINFORMATION or MB_OK);
      exit;
    end;
end;

procedure Tupf.gua1Click(Sender: TObject);
var product_no,no:string;
begin
  decnexx:=gyjc(getdecision);
  for i:=0 to 3 do
  begin
   product_no:=decnexx[i];
   for j:=1 to length(decnexx[i]) do
   begin
    no:=copy(decnexx[i],j,1);
    Q_all.Close;
    Q_all.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct where product_no='''+no+'''';
    Q_all.Open;
    if not Q_all.IsEmpty then
      Q_all.Edit;
      if i=0  then  Q_all.FieldByName('decision_ex').asstring:='good';
      if i=1  then  Q_all.FieldByName('decision_ex').asstring:='poor';
      if i=2  then  Q_all.FieldByName('decision_ex').asstring:='good,excel';
     Q_all.CheckBrowseMode;
     Q_all.ExecSQL;
   end;
  end;
  Q_product.Close;
  Q_product.SQL.Text:='select * FROM '+DatabaseName+'decision_reduct';
  Q_product.Open;
  
end;

function Tupf.getdecision:TDataVar;
var good,poor,excel:string;
    decision:TDataVar;
begin
  Q_all.Close;
  Q_all.SQL.Text:='select * FROM '+DatabaseName+'decision where decision=''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 where decision=''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 where decision=''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 Tupf.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;

end.



⌨️ 快捷键说明

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