1 (edited by domebil 2018-08-17 07:08:07)

Topic: the following script does not read the € ° symbols even if inserted in

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

Re: the following script does not read the € ° symbols even if inserted in

the following script does not read the € ° symbols even if inserted in the text

Domebil

Re: the following script does not read the € ° symbols even if inserted in

Please attach your project and CSV file for test.

Dmitry.

4 (edited by domebil 2018-08-17 14:48:00)

Re: the following script does not read the € ° symbols even if inserted in

I send you the project, it includes CSV
If you delete 1 and 2 product it will work otherwise

Post's attachments

Attachment icon prova.rar 332.82 kb, 332 downloads since 2018-08-17 

Domebil

Re: the following script does not read the € ° symbols even if inserted in

Encoding of CSV file is ANSI.
Please change it to UTF-8, you can do it using Notepad++ (Menu: Encoding > Convert to UTF-8)

Dmitry.

Re: the following script does not read the € ° symbols even if inserted in

thank you so much! It works

Domebil