try
{
DecimalFormat df = new DecimalFormat("00.##");
DecimalFormat df2 = new DecimalFormat("00.00");
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc,new FileOutputStream("C:\\Rechnungen\\test.pdf"));
doc.open();
Graphic line1 = new Graphic();
double widthd = 0.5;
String widths = String.valueOf(widthd);
float width = Float.parseFloat(widths);
Color bg = Color.BLACK;
float x1 = 50;
float x2 = 555;
float y1 = 525;
line1.drawHorizontalLine(width,bg,x1,x2,y1);
doc.add(line1);
Double[] Gesamtpreis = new Double[111111];
int zaehler = -1;
float y = 522;
int row = jTable1.getRowCount();
int rowcount;
for(rowcount = 0;rowcount <= row;rowcount++)
{
int col = 0;
int col2 = 6;
String p = String.valueOf(jTable1.getModel().getValueAt(rowcount,col));
String RKZ = String.valueOf(jTable1.getModel().getValueAt(rowcount,col2));
if(p.equals("true")&&RKZ.equals("true"))
{
JOptionPane.showMessageDialog(null,"Es sind Positionen ausgewählt, die bereits geliefert worden sind.\nBitte korrigieren Sie Ihre Angaben!","Hinweis",JOptionPane.INFORMATION_MESSAGE);
}
else if(p.equals("true")&&RKZ.equals("false"))
{
zaehler++;
y = y-15;
int col3 = 22;
int col4 = 9;
int col5 = 10;
int col6 = 11;
int col7 = 15;
int col8 = 20;
int col9 = 12;
String LSD = String.valueOf(jTable1.getModel().getValueAt(rowcount,col3));
String Bez = String.valueOf(jTable1.getModel().getValueAt(rowcount,col4));
String BNr = String.valueOf(jTable1.getModel().getValueAt(rowcount,col5));
String Po = String.valueOf(jTable1.getModel().getValueAt(rowcount,col6));
String best = String.valueOf(jTable1.getModel().getValueAt(rowcount,col7));
String IDNR = String.valueOf(jTable1.getModel().getValueAt(rowcount,col8));
String Bet = String.valueOf(jTable1.getModel().getValueAt(rowcount,col9));
Double Betrag = Double.parseDouble(Bet);
Double bestellt = Double.parseDouble(best);
Double Gesamt = Betrag*bestellt;
String Ges = String.valueOf(df2.format(Gesamt));
Gesamtpreis[zaehler] = Gesamt;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"/n Unable to load Driver","Fehler",JOptionPane.ERROR_MESSAGE);
}
try
{
String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname;
conn = DriverManager.getConnection(url,user,pw);
Statement stmt = conn.createStatement();
String sql=("SELECT * FROM lieferantenstamm");
ResultSet rs = stmt.executeQuery(sql);
rs.next();
String Anrede = rs.getString("lieferantenstamm.Anrede");
String Name1 = rs.getString("lieferantenstamm.Name1");
String Name2 = rs.getString("lieferantenstamm.Name2");
String Strasse = rs.getString("lieferantenstamm.Strasse");
String Hausnr = rs.getString("lieferantenstamm.Hausnr");
String PLZ = rs.getString("lieferantenstamm.PLZ");
String Ort = rs.getString("lieferantenstamm.Ort");
String LNr = rs.getString("lieferantenstamm.lieferantennr");
String KNr = rs.getString("lieferantenstamm.Kundennummer");
String sql2 = "SELECT * FROM rechnungsnummer_fortlaufend";
ResultSet rs2 = stmt.executeQuery(sql2);
rs2.next();
String RENr = rs2.getString("RENr");
String sql3 = "SELECT * FROM firmendaten";
ResultSet rs3 = stmt.executeQuery(sql3);
rs3.next();
String UIN = rs3.getString("firmendaten.UstIdentNr");
String Steuer = rs3.getString("firmendaten.Steuernummer");
PdfContentByte cb = writer.getDirectContent();
BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN,BaseFont.CP1250,BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf,12);
cb.setTextMatrix(50, 655);
cb.showText(Anrede);
cb.setTextMatrix(50, 635);
cb.showText(Name1);
usw.
float ky = cb.getYTLM();
if(ky<=70.0)
{
doc.newPage();
y = 507;
Graphic line2 = new Graphic();
double widthd2 = 0.5;
String widths2 = String.valueOf(widthd);
float width2 = Float.parseFloat(widths);
Color bg2 = Color.BLACK;
float x12 = 50;
float x22 = 545;
float y12 = 525;
line2.drawHorizontalLine(width2,bg2,x12,x22,y12);
doc.add(line2);
cb.beginText();
cb.setFontAndSize(bf,12);
cb.setTextMatrix(50, 655);
cb.showText(Anrede);
cb.setTextMatrix(50, 635);
cb.showText(Name1);
cb.setTextMatrix(118, 635);
cb.showText(Name2);
usw.
}
cb.endText();
}
catch(DocumentException e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"\n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"\n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"\n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
}
}
doc.close();
try
{
String t = "C:\\Rechnungen\\test.pdf";
Runtime rt = Runtime.getRuntime();
Process p1 = rt.exec("cmd.exe /c start "+t);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
int u = JOptionPane.showConfirmDialog(null,"Ist die Rechnung in Ordnung, kann das Kennzeichen gesetzt werden?","Hinweis",JOptionPane.YES_NO_OPTION);
if(u == JOptionPane.YES_OPTION)
{
if(tag<10&&monat<10)//Wenn die Bedingung zutrifft, geschieht folgendes
{
try
{
int row1 = jTable1.getRowCount();
int rowcount1;
String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname;
conn = DriverManager.getConnection(url,user,pw);
Statement stmt = conn.createStatement();
stmt.executeUpdate("UPDATE rechnungsnummer_fortlaufend SET RENr=RENr+1");
for(rowcount1 = 0;rowcount1 <= row1;rowcount1++)
{
int col = 0;
String o = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col));
if(o.equals("true"))
{
int col1 = 10;
int col2 = 11;
String date = String.valueOf("0"+tag+".0"+monat+"."+jahr);
String BNr1 = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col1));
String Po1 = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col2));
stmt.executeUpdate("UPDATE rechnungsnummer_fortlaufend SET RENr=RENr+1");
ResultSet rs2 = stmt.executeQuery("SELECT RENr FROM rechnungsnummer_fortlaufend");
rs2.next();
String RENr = rs2.getString("RENr");
stmt.executeUpdate("UPDATE alle_auftraege SET RENr = "+RENr+",REKz = true,REDatum = '"+date+"' WHERE BestNr LIKE '"+BNr1+"' AND Position ="+Po1);
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
}
else if(tag<10)
{
try
{
String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname;
conn = DriverManager.getConnection(url,user,pw);
Statement stmt = conn.createStatement();
stmt.executeUpdate("UPDATE rechnungsnummer_fortlaufend SET RENr=RENr+1");
int row1 = jTable1.getRowCount();
int rowcount1;
for(rowcount1 = 0;rowcount1 <= row1;rowcount1++)
{
int col = 0;
String o = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col));
if(o.equals("true"))
{
int col1 = 10;
int col2 = 11;
String date = String.valueOf("0"+tag+"."+monat+"."+jahr);
String BNr1 = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col1));
String Po1 = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col2));
ResultSet rs2 = stmt.executeQuery("SELECT RENr FROM rechnungsnummer_fortlaufend");
rs2.next();
String RENr = rs2.getString("RENr");
stmt.executeUpdate("UPDATE alle_auftraege SET RENr = "+RENr+",REKz = true,REDatum = '"+date+"' WHERE BestNr LIKE '"+BNr1+"' AND Position ="+Po1);
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"/n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
}
else if(monat<10)
{
try
{
String url = "jdbc:mysql://"+hostname+":"+port+"/"+dbname;
conn = DriverManager.getConnection(url,user,pw);
Statement stmt = conn.createStatement();
stmt.executeUpdate("UPDATE rechnungsnummer_fortlaufend SET RENr=RENr+1");
int row1 = jTable1.getRowCount();
int rowcount1;
for(rowcount1 = 0;rowcount1 <= row1;rowcount1++)
{
int col = 0;
String o = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col));
if(o.equals("true"))
{
int col1 = 10;
int col2 = 11;
String date = String.valueOf(tag+".0"+monat+"."+jahr);
String BNr1 = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col1));
String Po1 = String.valueOf(jTable1.getModel().getValueAt(rowcount1,col2));
ResultSet rs2 = stmt.executeQuery("SELECT RENr FROM rechnungsnummer_fortlaufend");
rs2.next();
String RENr = rs2.getString("RENr");
stmt.executeUpdate("UPDATE alle_auftraege SET RENr = "+RENr+",REKz = true,REDatum = '"+date+"' WHERE BestNr LIKE '"+BNr1+"' AND Position ="+Po1);
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"/n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
}
}
}
catch(DocumentException e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"/n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+"/n"+e.getStackTrace(),"Fehler",JOptionPane.ERROR_MESSAGE);
}