Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit principal;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, db, sqldb, odbcconn, mysql50conn, mysql56conn, FileUtil,
- Forms, Controls, Graphics, Dialogs, StdCtrls, DBGrids, DbCtrls, ComCtrls,
- ExtCtrls, ZConnection, ZDataset, IniFiles, regexpr, LConvEncoding;
- type
- { TfrmMinerar }
- TfrmMinerar = class(TForm)
- btnParametros: TButton;
- btnMarcas: TButton;
- btnModelos: TButton;
- btnPotencias: TButton;
- Button1: TButton;
- DModelo: TDataSource;
- DBLModelo: TDBLookupComboBox;
- DMarca: TDataSource;
- DPotencia: TDataSource;
- DBLMarca: TDBLookupComboBox;
- DBPotencia: TDBLookupComboBox;
- edtAnomes: TEdit;
- edtCNM: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Potencia: TLabel;
- Marca: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- lblcount: TLabel;
- ProgressBar1: TProgressBar;
- TimerPotencia: TTimer;
- TimerModelo: TTimer;
- TimerMarcas: TTimer;
- TimerParametros: TTimer;
- ZConnection1: TZConnection;
- ZModelomodelo: TStringField;
- ZPotenciapotencia: TStringField;
- ZQuery1: TZQuery;
- ZQuery1id: TLongintField;
- ZQuery1marca: TStringField;
- ZQuery1modelo: TStringField;
- ZQuery1nome: TStringField;
- ZQuery1potencia: TStringField;
- ZQuery2: TZQuery;
- ZQuery3: TZQuery;
- ZMarca: TZQuery;
- ZMarcamarca: TStringField;
- ZPotencia: TZQuery;
- ZModelo: TZQuery;
- ZQuery4: TZQuery;
- procedure btnMarcasClick(Sender: TObject);
- procedure btnModelosClick(Sender: TObject);
- procedure btnParametrosClick(Sender: TObject);
- procedure btnPotenciasClick(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure DBLMarcaChange(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- function Check( palavra,texto:String):Boolean;
- function CheckMarca( palavra,texto:String):Boolean;
- function CheckNovo( palavra,texto:String):Boolean;
- procedure TimerMarcasTimer(Sender: TObject);
- procedure TimerModeloTimer(Sender: TObject);
- procedure TimerParametrosTimer(Sender: TObject);
- procedure TimerPotenciaTimer(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- frmMinerar: TfrmMinerar;
- ptotal,pcontador,registro,total:Integer;
- estatus,ativo:Boolean;
- implementation
- {$R *.lfm}
- { TfrmMinerar }
- procedure TfrmMinerar.FormCreate(Sender: TObject);
- var
- ArqIni: TIniFile;
- begin
- try
- ArqIni := TIniFile.Create('banco.ini');
- ZConnection1.HostName:= ArqIni.ReadString('DATABASE','host','');
- ZConnection1.User:= ArqIni.ReadString('DATABASE','user','');
- ZConnection1.Password:= ArqIni.ReadString('DATABASE','senha','');
- ZConnection1.Database:= ArqIni.ReadString('DATABASE','database','');
- ZConnection1.Protocol:= ArqIni.ReadString('DATABASE','driver','');
- ZConnection1.Port:= ArqIni.ReadInteger('DATABASE','porta',3306);
- ZConnection1.LibraryLocation:= ArqIni.ReadString('DATABASE','lib','');
- ZConnection1.Connect;
- ZMarca.Open;
- ZModelo.Open;
- ZPotencia.Open;
- except
- ShowMessage('N�o foi possivel se cnectar ao banco');
- end;
- end;
- function TfrmMinerar.Check(palavra, texto: String): Boolean;
- var
- regex:TRegExpr;
- begin
- regex:=TRegExpr.Create;
- regex.Expression:= '.'+ISO_8859_15ToUTF8(UpperCase(palavra))+'.';
- // ShowMessage(BoolToStr(regex.Exec(texto)));
- result := regex.Exec(ISO_8859_15ToUTF8(UpperCase(texto)));
- end;
- function TfrmMinerar.CheckMarca(palavra, texto: String): Boolean;
- var
- regex:TRegExpr;
- begin
- regex:=TRegExpr.Create;
- regex.Expression:= '.*'+UpperCase(ISO_8859_15ToUTF8(palavra))+'.*';
- // ShowMessage(BoolToStr(regex.Exec(texto)));
- result := regex.Exec(UpperCase(ISO_8859_15ToUTF8(texto)));
- end;
- function TfrmMinerar.CheckNovo(palavra, texto: String): Boolean;
- var
- regex:TRegExpr;
- begin
- regex:=TRegExpr.Create;
- regex.Expression:= '\b'+UpperCase(ISO_8859_15ToUTF8(palavra))+'\b';
- // ShowMessage(BoolToStr(regex.Exec(texto)));
- result := regex.Exec(UpperCase(ISO_8859_15ToUTF8(texto)));
- end;
- procedure TfrmMinerar.TimerMarcasTimer(Sender: TObject);
- var
- lsql,nome,usql,descricao,atsql :string;
- i,k: integer;
- begin
- if estatus then
- TimerMarcas.Interval:=200000000;
- begin
- estatus:= false;
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <> '+QuotedStr('todos')+' AND tratado = 0 AND marca <> '+QuotedStr('')+' LIMIT 10 ';
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- k:=ZQuery1.RecordCount;
- i:=0;
- if k > 0 then
- begin
- while not ZQuery1.EOF do
- begin
- inc(i);
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- ZQuery2.Close;
- ZQuery2.SQL.Clear;
- ZQuery2.SQL.Add(lsql);
- ZQuery2.Open;
- nome := ZQuery1.FieldByName('nome').AsString;
- while not ZQuery2.EOF do
- begin
- inc(registro);
- lblcount.Caption:= IntToStr(registro)+'/'+IntToStr(total);
- ProgressBar1.Position:= ProgressBar1.Position + 1; //sempre adciona um na contagem
- Application.ProcessMessages;
- descricao:= ZQuery2.FieldByName('descricao_do_produto').AsString;
- if(CheckMarca(nome,descricao)) then
- begin
- usql := 'UPDATE importcao ';
- usql := usql+'set marca = :xmarca';
- usql := usql+' where id = :xid';
- ZQuery3.Close;
- ZQuery3.SQL.Clear;
- ZQuery3.SQL.Add(usql);
- ZQuery3.ParamByName('xmarca').Value:= ZQuery1marca .AsString;
- ZQuery3.ParamByName('xid').Value:= ZQuery2.FieldByName('id').AsInteger;
- ZQuery3.ExecSQL;
- ZQuery3.SQL.SaveToFile('sql_saida.txt');
- end;
- ZQuery2.Next;
- end;
- atsql := 'update parametros set tratado = 1 where id = '+ZQuery1.FieldByName('id').AsString;
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- if i = 10 then
- begin
- TimerMarcas.Enabled:= false;
- TimerMarcas.Interval:=1000;
- TimerMarcas.Enabled:= true;
- estatus:= true;
- end;
- ZQuery1.Next;
- end;
- end
- else
- begin
- ShowMessage('Fim');
- ProgressBar1.Position := 0;
- lblcount.Caption:= '0/0';
- atsql := 'update parametros set tratado = 0 ';
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- Application.ProcessMessages;
- TimerMarcas.Enabled:=false;
- end;
- end;
- end;
- procedure TfrmMinerar.TimerModeloTimer(Sender: TObject);
- var
- lsql,nome,usql,descricao,atsql :string;
- i,k: integer;
- begin
- if estatus then
- TimerModelo.Interval:=200000000;
- begin
- estatus:= false;
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <> '+QuotedStr('todos')+' AND tratado = 0 AND modelo <> '+QuotedStr('')+' LIMIT 10 ';
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- k:=ZQuery1.RecordCount;
- i:=0;
- if k > 0 then
- begin
- while not ZQuery1.EOF do
- begin
- inc(i);
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- ZQuery2.Close;
- ZQuery2.SQL.Clear;
- ZQuery2.SQL.Add(lsql);
- ZQuery2.Open;
- nome := ZQuery1.FieldByName('nome').AsString;
- while not ZQuery2.EOF do
- begin
- inc(registro);
- lblcount.Caption:= IntToStr(registro)+'/'+IntToStr(total);
- ProgressBar1.Position:= ProgressBar1.Position + 1; //sempre adciona um na contagem
- Application.ProcessMessages;
- descricao:= ZQuery2.FieldByName('descricao_do_produto').AsString;
- if(CheckNovo(nome,descricao)) then
- begin
- usql := 'UPDATE importcao set modelo = :xmodelo where id = :xid';
- ZQuery3.Close;
- ZQuery3.SQL.Clear;
- ZQuery3.SQL.Add(usql);
- ZQuery3.ParamByName('xmodelo').Value:= ZQuery1modelo.AsString;
- ZQuery3.ParamByName('xid').Value:= ZQuery2.FieldByName('id').AsInteger;
- ZQuery3.ExecSQL;
- ZQuery3.SQL.SaveToFile('sql_saida.txt');
- end;
- ZQuery2.Next;
- end;
- atsql := 'update parametros set tratado = 1 where id = '+ZQuery1.FieldByName('id').AsString;
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- if i = 10 then
- begin
- TimerModelo.Enabled:= false;
- TimerModelo.Interval:=1000;
- TimerModelo.Enabled:= true;
- estatus:= true;
- end;
- ZQuery1.Next;
- end;
- end
- else
- begin
- ShowMessage('Fim');
- ProgressBar1.Position := 0;
- lblcount.Caption:= '0/0';
- TimerModelo.Enabled:=false;
- atsql := 'update parametros set tratado = 0 ';
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- end;
- end;
- end;
- procedure TfrmMinerar.TimerParametrosTimer(Sender: TObject);
- var
- lsql,nome,usql,descricao,atsql :string;
- i,k: integer;
- begin
- if estatus then
- TimerParametros.Interval:=120000;
- begin
- estatus:= false;
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <>'+QuotedStr('todos')+ ' AND tratado = 0 LIMIT 10';
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- k:=ZQuery1.RecordCount;
- i:=0;
- if k > 0 then
- begin
- while not ZQuery1.EOF do
- begin
- inc(i);
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text)+' AND tratado = 0 LIMIT 10000';
- ZQuery2.Close;
- ZQuery2.SQL.Clear;
- ZQuery2.SQL.Add(lsql);
- ZQuery2.Open;
- nome := ZQuery1.FieldByName('nome').AsString;
- while not ZQuery2.EOF do
- begin
- inc(registro);
- lblcount.Caption:= IntToStr(registro)+'/'+IntToStr(total);
- ProgressBar1.Position:= ProgressBar1.Position + 1; //sempre adciona um na contagem
- Application.ProcessMessages;
- descricao:= ZQuery2.FieldByName('descricao_do_produto').AsString;
- if(CheckNovo(nome,descricao)) then
- begin
- usql := 'UPDATE importcao ';
- if (ZQuery1marca .AsString <> '') then
- usql := usql+'set marca = '+QuotedStr(ZQuery1marca .AsString);
- if (ZQuery1marca .AsString = '') and (ZQuery1modelo .AsString <> '') then
- usql := usql+'set modelo = '+QuotedStr(ZQuery1modelo .AsString);
- if (ZQuery1marca .AsString <>'') and (ZQuery1modelo .AsString <> '') then
- usql := usql+' , modelo = '+QuotedStr(ZQuery1modelo .AsString);
- if (ZQuery1potencia .AsString <> '') and (ZQuery1marca .AsString = '') and (ZQuery1modelo .AsString = '') then
- usql := usql+'set potencia = '+QuotedStr(ZQuery1potencia .AsString);
- if (ZQuery1potencia .AsString <> '') and ((ZQuery1marca .AsString <> '') or (ZQuery1modelo .AsString <> '')) then
- usql := usql+', potencia = '+QuotedStr(ZQuery1potencia .AsString);
- usql := usql+' where id = :xid';
- ZQuery3.Close;
- ZQuery3.SQL.Clear;
- ZQuery3.SQL.Add(usql);
- ZQuery3.ParamByName('xid').Value:= ZQuery2.FieldByName('id').AsInteger;
- ZQuery3.ExecSQL;
- // ZQuery3.SQL.SaveToFile('sql_saida.txt');
- end;
- ZQuery2.Next;
- end;
- atsql := 'update parametros set tratado = 1 where id = '+ZQuery1.FieldByName('id').AsString;
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- if i = 10 then
- begin
- TimerParametros.Enabled:= false;
- TimerParametros.Interval:=1000;
- TimerParametros.Enabled:= true;
- estatus:= true;
- end;
- ZQuery1.Next;
- end;
- end
- else
- begin
- ShowMessage('Fim');
- ProgressBar1.Position := 0;
- lblcount.Caption:= '0/0';
- atsql := 'update parametros set tratado = 0 ';
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- Application.ProcessMessages;
- TimerParametros.Enabled:=false;
- end;
- end;
- end;
- procedure TfrmMinerar.TimerPotenciaTimer(Sender: TObject);
- var
- lsql,nome,usql,descricao,atsql :string;
- i,k: integer;
- begin
- if estatus then
- TimerPotencia.Interval:=200000000;
- begin
- estatus:= false;
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <> '+QuotedStr('todos')+' AND tratado = 0 AND potencia <> '+QuotedStr('')+' LIMIT 10 ';
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- k:=ZQuery1.RecordCount;
- i:=0;
- if k > 0 then
- begin
- while not ZQuery1.EOF do
- begin
- inc(i);
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- ZQuery2.Close;
- ZQuery2.SQL.Clear;
- ZQuery2.SQL.Add(lsql);
- ZQuery2.Open;
- nome := ZQuery1.FieldByName('nome').AsString;
- while not ZQuery2.EOF do
- begin
- inc(registro);
- lblcount.Caption:= IntToStr(registro)+'/'+IntToStr(total);
- ProgressBar1.Position:= ProgressBar1.Position + 1; //sempre adciona um na contagem
- Application.ProcessMessages;
- descricao:= ZQuery2.FieldByName('descricao_do_produto').AsString;
- if(CheckNovo(nome,descricao)) then
- begin
- usql := 'UPDATE importcao set potencia = :xpotencia where id = :xid';
- ZQuery3.Close;
- ZQuery3.SQL.Clear;
- ZQuery3.SQL.Add(usql);
- ZQuery3.ParamByName('xpotencia').Value:= ZQuery1potencia.AsString;
- ZQuery3.ParamByName('xid').Value:= ZQuery2.FieldByName('id').AsInteger;
- ZQuery3.ExecSQL;
- ZQuery3.SQL.SaveToFile('sql_saida.txt');
- end;
- ZQuery2.Next;
- end;
- atsql := 'update parametros set tratado = 1 where id = '+ZQuery1.FieldByName('id').AsString;
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- if i = 10 then
- begin
- TimerPotencia.Enabled:= false;
- TimerPotencia.Interval:=1000;
- TimerPotencia.Enabled:= true;
- estatus:= true;
- end;
- ZQuery1.Next;
- end;
- end
- else
- begin
- ShowMessage('Fim');
- ProgressBar1.Position := 0;
- lblcount.Caption:= '0/0';
- TimerPotencia.Enabled:=false;
- atsql := 'update parametros set tratado = 0 ';
- ZQuery4.Close;
- ZQuery4.SQL.Clear;
- ZQuery4.SQL.Add(atsql);
- ZQuery4.ExecSQL;
- end;
- end;
- end;
- procedure TfrmMinerar.btnParametrosClick(Sender: TObject);
- var
- lsql:string;
- begin
- ativo:= true;
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <>'+QuotedStr('todos')+ ' AND tratado = 0';
- pcontador := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- ptotal:= ZQuery1.RecordCount;
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- registro := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Text:= lsql ;
- ZQuery1.Open;
- registro:= ZQuery1.RecordCount;
- total := ptotal * registro ;
- ProgressBar1.Position:=0;//posiciona a progress bar na
- ProgressBar1.Max:=total;
- lblcount.Caption:= IntToStr(1)+'/'+IntToStr(total);
- estatus:= true;
- TimerParametros.Interval:= 1000;
- TimerParametros.Enabled:= true;
- end;
- procedure TfrmMinerar.btnPotenciasClick(Sender: TObject);
- var
- lsql:string;
- begin
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <> '+QuotedStr('todos')+'AND tratado = 0 AND potencia <> '+QuotedStr('');
- ptotal := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- ptotal:= ZQuery1.RecordCount;
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- registro := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- registro:= ZQuery1.RecordCount;
- total := ptotal * registro ;
- ProgressBar1.Position:=0;//posiciona a progress bar na
- ProgressBar1.Max:=total;
- lblcount.Caption:= IntToStr(1)+'/'+IntToStr(total);
- estatus:= true;
- TimerPotencia.Interval:= 1000;
- TimerPotencia.Enabled:= true;
- end;
- procedure TfrmMinerar.btnMarcasClick(Sender: TObject);
- var
- lsql:string;
- begin
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <> '+QuotedStr('todos')+'AND tratado = 0 AND marca <> '+QuotedStr('');
- ptotal := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- ptotal:= ZQuery1.RecordCount;
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- registro := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- registro:= ZQuery1.RecordCount;
- total := ptotal * registro ;
- ProgressBar1.Position:=0;//posiciona a progress bar na
- ProgressBar1.Max:=total;
- lblcount.Caption:= IntToStr(1)+'/'+IntToStr(total);
- estatus:= true;
- TimerMarcas.Interval:= 1000;
- TimerMarcas.Enabled:= true;
- end;
- procedure TfrmMinerar.btnModelosClick(Sender: TObject);
- var
- lsql:string;
- begin
- lsql := 'SELECT * FROM parametros where nome <> '+QuotedStr('vazio')+' AND nome <> '+QuotedStr('todos')+'AND tratado = 0 AND modelo <> '+QuotedStr('');
- ptotal := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- ptotal:= ZQuery1.RecordCount;
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- registro := 0;
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- registro:= ZQuery1.RecordCount;
- total := ptotal * registro ;
- ProgressBar1.Position:=0;//posiciona a progress bar na
- ProgressBar1.Max:=total;
- lblcount.Caption:= IntToStr(1)+'/'+IntToStr(total);
- estatus:= true;
- TimerModelo.Interval:= 1000;
- TimerModelo.Enabled:= true;
- end;
- procedure TfrmMinerar.Button1Click(Sender: TObject);
- var
- lsql,nome,usql,descricao :string;
- i,k: integer;
- begin
- lsql := 'SELECT * FROM `parametros` WHERE nome <> '+QuotedStr('')+' and nome <> '+QuotedStr('todos')+' and nome <> '+QuotedStr('') ;
- if DBLMarca.Text <> '' then
- lsql := lsql+' AND marca = '+QuotedStr(DBLMarca.Text);
- if DBLModelo.Text <> '' then
- lsql := lsql+' AND modelo = '+QuotedStr(DBLModelo.Text);
- if DBPotencia.Text <> '' then
- lsql := lsql+' AND potencia = '+QuotedStr(DBPotencia.Text);
- ZQuery1.Close;
- ZQuery1.SQL.Clear;
- ZQuery1.SQL.Add(lsql);
- ZQuery1.Open;
- k:= ZQuery1.RecordCount;
- i:=0;
- ProgressBar1.Position:=0;//posiciona a progress bar na posicao 0
- ProgressBar1.Max:= k;//quantidade maxima de numeros
- while not ZQuery1.EOF do
- begin
- inc(i);
- lblcount.Caption:= IntToStr(i)+'/'+IntToStr(k);
- ProgressBar1.Position:= ProgressBar1.Position + 1; //sempre adciona um na contagem
- Application.ProcessMessages;
- lsql := 'SELECT * from importcao where anomes = '+QuotedStr(edtAnomes.Text)+' AND codncm = '+QuotedStr(edtCNM.Text);
- ZQuery2.Close;
- ZQuery2.SQL.Clear;
- ZQuery2.SQL.Add(lsql);
- ZQuery2.Open;
- nome := ZQuery1.FieldByName('nome').AsString;
- while not ZQuery2.EOF do
- begin
- descricao:= ZQuery2.FieldByName('descricao_do_produto').AsString;
- if(Check(nome,descricao)) then
- begin
- usql := 'UPDATE importcao ';
- if (DBLMarca.Text <> '') and (DBLModelo.Text = '') and (DBPotencia.Text = '') then
- begin
- if ZQuery1marca .AsString <> '' then
- usql := usql+'set marca = :xmarca';
- if (ZQuery1marca .AsString = '') and (ZQuery1modelo .AsString <> '') then
- usql := usql+'set modelo = :xmodelo';
- if (ZQuery1marca .AsString <>'') and (ZQuery1modelo .AsString <> '') then
- usql := usql+' , modelo = :xmodelo';
- if (ZQuery1potencia .AsString <> '') and (ZQuery1marca .AsString = '') and (ZQuery1modelo .AsString = '') then
- usql := usql+'set potencia = :xpotencia';
- if (ZQuery1potencia .AsString <> '') and ((ZQuery1marca .AsString <> '') or (ZQuery1modelo .AsString <> '')) then
- usql := usql+' , potencia = :xpotencia';
- end;
- // modelo
- if (DBLModelo.Text <> '') and (DBLMarca.Text = '') and (DBPotencia.Text = '') then
- usql := usql+'set modelo = :xmodelo';
- if (DBPotencia.Text <> '') and (DBLModelo.Text = '') and (DBLMarca.Text = '') then
- usql := usql+'set potencia = :xpotencia';
- usql := usql+' where id = :xid';
- ZQuery3.Close;
- ZQuery3.SQL.Clear;
- ZQuery3.SQL.Add(usql);
- if (DBLMarca.Text <> '') and (DBLModelo.Text = '') and (DBPotencia.Text = '') then
- begin
- if ZQuery1marca .AsString <> '' then
- ZQuery3.ParamByName('xmarca').Value:= ZQuery1marca .AsString;
- if ZQuery1modelo .AsString <> '' then
- ZQuery3.ParamByName('xmodelo').Value:= ZQuery1modelo.AsString;
- if ZQuery1potencia.AsString <> '' then
- ZQuery3.ParamByName('xpotencia').Value:= ZQuery1potencia.AsString;
- end;
- if (DBLModelo.Text <> '') and (DBLMarca.Text = '') and (DBPotencia.Text = '') then
- begin
- if ZQuery1modelo .AsString <> '' then
- ZQuery3.ParamByName('xmodelo').Value:= ZQuery1modelo.AsString;
- end;
- if (DBPotencia.Text <> '') and (DBLModelo.Text = '') and (DBLMarca.Text = '') then
- begin
- if ZQuery1potencia.AsString <> '' then
- ZQuery3.ParamByName('xpotencia').Value:= ZQuery1potencia.AsString;
- end;
- ZQuery3.ParamByName('xid').Value:= ZQuery2.FieldByName('id').AsInteger;
- ZQuery3.ExecSQL;
- ZQuery3.SQL.SaveToFile('sql_saida.txt');
- end;
- ZQuery2.Next;
- end;
- ZQuery1.Next;
- // zquery2.SQL.SaveToFile('sql_saida.txt');
- {
- ZQuery2.ParamByName('xmarca').Value:= ZQuery1marca .AsString;
- ZQuery2.ParamByName('xmodelo').Value:= ZQuery1modelo.AsString;
- ZQuery2.ParamByName('xpotencia').Value:= ZQuery1potencia.AsString;
- ZQuery2.ParamByName('xnome').AsString := QuotedStr('%'+ZQuery1.FieldByName('nome').AsString+'%');
- ZQuery2.ParamByName('xncm').AsString:= edtCNM.Text;
- }
- end;
- ShowMessage('Fim');
- ProgressBar1.Position := 0;
- lblcount.Caption:= '0/0';
- end;
- procedure TfrmMinerar.Button2Click(Sender: TObject);
- begin
- if TimerParametros.Enabled then
- begin
- TimerParametros.Enabled := false;
- ativo:= false;
- ZConnection1.Disconnect;
- ShowMessage('Minera��o pausada');
- end
- else
- begin
- ativo:= true;
- ZConnection1.Connect;
- TimerParametros.Enabled := false;
- TimerParametros.Interval:= 1000;
- TimerParametros.Enabled := true;
- ShowMessage('Minera��o em andamento');
- end;
- if TimerMarcas.Enabled then
- begin
- TimerMarcas.Enabled := false;
- end
- else
- begin
- TimerMarcas.Enabled := false;
- TimerMarcas.Interval:= 1000;
- TimerMarcas.Enabled := true;
- end;
- if TimerModelo.Enabled then
- begin
- TimerModelo.Enabled := false;
- end
- else
- begin
- TimerModelo.Enabled := false;
- TimerModelo.Interval:= 1000;
- TimerModelo.Enabled := true;
- end;
- if TimerPotencia.Enabled then
- begin
- TimerPotencia.Enabled := false;
- end
- else
- begin
- TimerPotencia.Enabled := false;
- TimerPotencia.Interval:= 1000;
- TimerPotencia.Enabled := true;
- end;
- end;
- procedure TfrmMinerar.DBLMarcaChange(Sender: TObject);
- begin
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement