procedure TImportar.Button1Click(Sender: TObject);
var
xls : Variant;
iFila,Total,Puntero: Integer;
Porc: Real;
fLoop: Boolean;
Fecha: TDate;
Loteria: String;
NomZod: String;
Triple: String;
begin
if OpenDialog1.Execute then
begin
Button1.Enabled := False;
xls := CreateOleObject('Excel.Application');
xls.WorkBooks.Open( OpenDialog1.FileName );
xls.Visible := false;
fLoop := true;
iFila := 2;
Puntero := 0;
while fLoop do
begin
if VarToStr( xls.WorkSheets[1].Cells[iFila,1].Value ) = '' then
fLoop := false
else
begin
inc(iFila);
Label1.Caption := 'Procesando ...';
Label1.Update;
end;
end;
Total:=iFila;
ProgressBar1.Max:=iFila;
try
fLoop := true;
iFila := 2; while fLoop do
begin
if VarToStr( xls.WorkSheets[1].Cells[iFila,1].Value ) = '' then
fLoop := false
else
begin
Fecha:=StrtoDate(VarToStr( xls.WorkSheets[1].Cells[iFila,1].Value));
Loteria:=VarToStr( xls.WorkSheets[1].Cells[iFila,2].Value);
if (VarToStr( xls.WorkSheets[1].Cells[iFila,7].Value)) = '' then
NomZod := 'No Hay'
else
NomZod:=VarToStr( xls.WorkSheets[1].Cells[iFila,7].Value);
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Text:='SELECT * FROM Loterias WHERE (Fecha = :Fec) AND (Loteria = :Lot)';
Query1.ParamByName('Lot').asString := Loteria;
Query1.ParamByName('Fec').asDate := Fecha;
Query1.RequestLive := true;
Query1.Open;
if Query1.IsEmpty then
Begin
Query2.Close;
Query2.SQL.Clear;
Query2.SQL.Text:='SELECT NomLot FROM NombreLoterias WHERE (NomLot = :Lot)';
Query2.ParamByName('Lot').asString := Loteria;
Query2.RequestLive := true;
Query2.Open;
if Query2.IsEmpty then
Begin
Query2.Insert;
Query2.FieldByName('NomLot').AsString:=Loteria;
Query2.Post;
end;
Query3.Close;
Query3.SQL.Clear;
Query3.SQL.Text:='SELECT * FROM Zodiacales WHERE (NomZod = :Zod)';
Query3.ParamByName('Zod').asString := NomZod;
Query3.RequestLive := true;
Query3.Open;
if Query3.IsEmpty then
Begin
Query3.Insert;
Query3.FieldByName('NomZod').AsString := NomZod;
Query3.Post;
end;
Query1.Insert;
Query1.FieldByName('Id').AsInteger := Table1.RecordCount+1;
Query1.FieldByName('Fecha').AsDateTime := StrtoDate(VarToStr( xls.WorkSheets[1].Cells[iFila,1].Value));
Query1.FieldByName('Loteria').AsString := VarToStr( xls.WorkSheets[1].Cells[iFila,2].Value);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,3].Value);
Query1.FieldByName('ADia').AsString := completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,4].Value);
Query1.FieldByName('BDia').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,5].Value);
Query1.FieldByName('CDia').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,6].Value);
Query1.FieldByName('ZDia').AsString := VarToStr( xls.WorkSheets[1].Cells[iFila,7].Value);
Query1.FieldByName('ATarde').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,8].Value);
Query1.FieldByName('BTarde').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,9].Value);
Query1.FieldByName('CTarde').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,10].Value);
Query1.FieldByName('ZTarde').AsString := VarToStr( xls.WorkSheets[1].Cells[iFila,11].Value);
Query1.FieldByName('ANoche').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,12].Value);
Query1.FieldByName('BNoche').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,13].Value);
Query1.FieldByName('CNoche').AsString :=completarceros(triple);
triple:=VarToStr( xls.WorkSheets[1].Cells[iFila,14].Value);
Query1.FieldByName('ZNoche').AsString := VarToStr( xls.WorkSheets[1].Cells[iFila,15].Value);
Query1.Post;
end;
end;
inc(iFila);
inc(Puntero);
Porc:=IFila*100/Total;
Label1.Caption := FloattoStr(Trunc(Porc))+'%';
ProgressBar1.StepIt;
Label1.Update;
end
finally
xls.Quit
end;
Label1.Caption := 'Completado';
Label1.Update;
end
else
begin
Button1.Enabled := True;
Principal.Importar1.Enabled:=True;
Close;
end;
Query1.Destroy;
Query2.Destroy;
Query3.Destroy;
end;