89 lines
3.5 KiB
Java
89 lines
3.5 KiB
Java
|
|
import com.ablia.anag.Listino;
|
||
|
|
import com.ablia.anag.ListinoArticolo;
|
||
|
|
import com.ablia.art.Articolo;
|
||
|
|
import com.ablia.db.ApplParm;
|
||
|
|
import com.ablia.db.ApplParmFull;
|
||
|
|
import com.ablia.util.DbConsole;
|
||
|
|
import com.ablia.util.Vectumerator;
|
||
|
|
import java.sql.Time;
|
||
|
|
import java.util.StringTokenizer;
|
||
|
|
|
||
|
|
public class SalvaArticoliPerListino extends DbConsole {
|
||
|
|
public static void main(String[] args) {
|
||
|
|
SalvaArticoliPerListino bean = new SalvaArticoliPerListino();
|
||
|
|
bean.doImport();
|
||
|
|
System.exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void doImport() {
|
||
|
|
String db = "guidoreni";
|
||
|
|
int i = 0;
|
||
|
|
int se1 = 10;
|
||
|
|
int se2 = 100;
|
||
|
|
String hostname = "www.lanificiozanieri.eu";
|
||
|
|
String temp = getCi().readLine("Hostname (" + hostname + "):");
|
||
|
|
if (!temp.isEmpty())
|
||
|
|
hostname = temp;
|
||
|
|
temp = getCi().readLine("Database name (" + db + "):");
|
||
|
|
if (!temp.isEmpty())
|
||
|
|
db = temp;
|
||
|
|
System.out.println("Db: " + db);
|
||
|
|
ApplParmFull apTarget = new ApplParmFull(new ApplParm(3, "//" + hostname + "/" + db, "root", "root", 1, 10, 300));
|
||
|
|
apTarget.setDebug(false);
|
||
|
|
StringBuffer msg = new StringBuffer();
|
||
|
|
try {
|
||
|
|
Articolo bean = new Articolo(apTarget);
|
||
|
|
System.out.println("ciclo articoli");
|
||
|
|
Vectumerator<Articolo> vec = bean.findAll();
|
||
|
|
Listino lis = Listino.dammiListinoBase(apTarget);
|
||
|
|
System.out.println("Tot Record: " + vec.getTotNumberOfRecords());
|
||
|
|
while (vec.hasMoreElements()) {
|
||
|
|
Articolo row = (Articolo)vec.nextElement();
|
||
|
|
ListinoArticolo la = new ListinoArticolo(apTarget);
|
||
|
|
la.findByArticoloListino(row.getId_articolo(), lis.getId_listino());
|
||
|
|
la.setId_articolo(row.getId_articolo());
|
||
|
|
la.setId_listino(lis.getId_listino());
|
||
|
|
la.setPrezzoLA(row.getImportListinoPrezzoPubblico());
|
||
|
|
la.setPrezzoOffertaLA(row.getImportListinoPrezzoOfferta());
|
||
|
|
la.setDataScadenzaOffertaLA(row.getImportListinoDataScadenzaOfferta());
|
||
|
|
la.setAbbuonoPrezzoPubblicoLA(row.getImportListinoAbbuonoPrezzoPubblico());
|
||
|
|
la.setPercLA(row.getImportListinoPercSconto());
|
||
|
|
la.setDataCambiamentoPrezzoLA(row.getImportListinoDataCambiamentoPrezzo());
|
||
|
|
la.setAbbuonoPrezzoPubblicoLA(row.getImportAbbuonoPrezzoPubblico());
|
||
|
|
la.save();
|
||
|
|
i++;
|
||
|
|
if (se1 > 0 && i % se1 == 0)
|
||
|
|
System.out.print(".");
|
||
|
|
if (se2 > 0 && i % se2 == 0)
|
||
|
|
System.out.println(i);
|
||
|
|
}
|
||
|
|
System.out.println("fine ciclo \n" + msg.toString());
|
||
|
|
} catch (Exception e) {
|
||
|
|
e.printStackTrace();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected Time getTimeFromString(String theTime) {
|
||
|
|
try {
|
||
|
|
if (theTime.matches("[0-9][0-9][0-9][0-9]"))
|
||
|
|
theTime = String.valueOf(theTime.substring(0, 2)) + ":" + theTime.substring(2, 4);
|
||
|
|
if (theTime.matches("[0-9]{1,2}+:[0-9]{1,2}+")) {
|
||
|
|
StringTokenizer st = new StringTokenizer(theTime, ":");
|
||
|
|
int hour = Integer.parseInt(st.nextToken());
|
||
|
|
int min = Integer.parseInt(st.nextToken());
|
||
|
|
int sec = st.hasMoreElements() ? Integer.parseInt(st.nextToken()) : 0;
|
||
|
|
return new Time((long)((hour - 1) * 3600000 + min * 60000 + sec * 1000));
|
||
|
|
}
|
||
|
|
if (theTime.matches("[0-9]{1,2}+:[0-9]{1,2}+:[0-9]{1,2}+")) {
|
||
|
|
StringTokenizer st = new StringTokenizer(theTime, ":");
|
||
|
|
int hour = Integer.parseInt(st.nextToken());
|
||
|
|
int min = Integer.parseInt(st.nextToken());
|
||
|
|
int sec = st.hasMoreElements() ? Integer.parseInt(st.nextToken()) : 0;
|
||
|
|
return new Time((long)((hour - 1) * 3600000 + min * 60000 + sec * 1000));
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
} catch (Exception e) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|