procedure Prodotto_Button6_OnClick (Sender: string; var Cancel: boolean);
var
OpenDialog: TOpenDialog;
sl: TStringList;
arrStr: array of string;
i,c: integer;
CategoriaID: string;
FornitoreID: string;
sval: string;
begin
OpenDialog := TOpenDialog.Create(Prodotto);
if OpenDialog.Execute then
begin
sl := TStringList.Create;
sl.LoadFromFile (OpenDialog.FileName);
c := sl.Count - 1;
for i := 0 to c do
begin
arrStr := SplitString(sl[i], ';');
// Codice
if arrStr[0] <> '' then arrStr[0] := ''''+ ReplaceStr(arrStr[0], '''', '''''') + ''''
else arrStr[0] := 'NULL';
//prodotto
if arrStr[1] <> '' then arrStr[1] := ''''+ ReplaceStr(arrStr[1], '''', '''''') + ''''
else arrStr[1] := 'NULL';
// costo
arrStr[2] := ReplaceStr(arrStr[2], ',', '');
if arrStr[2] = '' then arrStr[2] := 'NULL';
//U.M:
if arrStr[3] <> '' then arrStr[3] := ''''+ ReplaceStr(arrStr[3], '''', '''''') + ''''
else arrStr[3] := 'NULL';
//imballaggio
if arrStr[4] <> '' then arrStr[4] := ''''+ ReplaceStr(arrStr[4], '''', '''''') + ''''
else arrStr[4] := 'NULL';
//IVA
if arrStr[5] <> '' then arrStr[5] := ''''+ ReplaceStr(arrStr[5], '''', '''''') + ''''
else arrStr[5] := 'NULL';
// Fornitore
FornitoreID := SQLExecute ('SELECT id FROM fornitore WHERE nomef LIKE "' + arrStr[6] +'"');
if FornitoreID = '' then FornitoreID:= 'NULL';
// categoria
CategoriaID := SQLExecute ('SELECT id FROM categoria WHERE categorie LIKE "' + arrStr[7] +'"');
if CategoriaID = '' then CategoriaID := 'NULL';
//disponibilita
if arrStr[8] <> '' then arrStr[8] := ''''+ ReplaceStr(arrStr[8], '''', '''''') + ''''
else arrStr[8] := 'NULL';
// check for dublicate
sval := SQLExecute('SELECT id FROM prodotti WHERE (cod = ' + arrStr[0] +') AND (prodotto = ' + arrStr[1] +') AND (prezzo = ' + arrStr[2]+ ')AND (unitadimisura = ' + arrStr[3]+ ') AND (imballo = ' + arrStr[4]+ ')AND (iva = ' + arrStr[5]+ ')AND (id_fornitore = ' + FornitoreID + ') AND (id_categoria = ' + CategoriaID + ')AND (stato = ' + arrStr[8]+ ') ;');
if sval = '' then SQLExecute ('INSERT INTO prodotti (cod, prodotto, prezzo, unitadimisura, imballo, iva, id_fornitore, id_categoria, stato ) VALUES (' + arrStr[0] +','+ arrStr[1] +','+arrStr[2]+','+arrStr[3]+','+arrStr[4]+','+arrStr[5]+','+ FornitoreID +','+ CategoriaID +','+arrStr[8]+');');
Prodotto.Button6.Caption := IntToStr(i+1) + ' di ' + IntToStr(c+1);
Application.ProcessMessages;
end;
sl.Free;
Prodotto.TableGrid1.dbUpdate;
ShowMessage(' Importati '+ IntToStr (c+1) + ' records.');
end;
OpenDialog.Free;
end;
Domebil