3 import java
.awt
.Cursor
;
4 import java
.awt
.event
.WindowEvent
;
5 import java
.awt
.event
.WindowListener
;
6 import java
.sql
.Connection
;
7 import java
.sql
.DriverManager
;
8 import java
.sql
.SQLException
;
9 import java
.util
.HashMap
;
11 import java
.util
.Properties
;
13 import javax
.swing
.JFrame
;
14 import javax
.swing
.JOptionPane
;
15 import javax
.swing
.UIManager
;
16 import javax
.swing
.UnsupportedLookAndFeelException
;
18 import org
.jdesktop
.swingworker
.SwingWorker
;
24 import CommonTools
.INIFile
;
25 import CommonTools
.INITool
;
26 import CommonTools
.SqlInfo
;
27 import CommonTools
.StartOOApplication
;
28 import CommonTools
.Verschluesseln
;
29 import RehaIO
.RehaIOMessages
;
30 import RehaIO
.RehaReverseServer
;
31 import RehaIO
.SocketClient
;
32 import ag
.ion
.bion
.officelayer
.application
.ILazyApplicationInfo
;
33 import ag
.ion
.bion
.officelayer
.application
.IOfficeApplication
;
34 import ag
.ion
.bion
.officelayer
.application
.OfficeApplicationException
;
35 import ag
.ion
.bion
.officelayer
.application
.OfficeApplicationRuntime
;
36 import ag
.ion
.bion
.officelayer
.document
.DocumentException
;
37 import ag
.ion
.bion
.officelayer
.document
.IDocument
;
38 import ag
.ion
.bion
.officelayer
.event
.ITerminateEvent
;
39 import ag
.ion
.bion
.officelayer
.event
.VetoTerminateListener
;
41 public class RehaSql
implements WindowListener
{
49 public static boolean DbOk
;
51 public static JFrame thisFrame
= null;
52 public Connection conn
;
53 public static RehaSql thisClass
;
55 public static IOfficeApplication officeapplication
;
57 public String dieseMaschine
= null;
59 public static String dbIpAndName = null;
60 public static String dbUser = null;
61 public static String dbPassword = null;
65 public final Cursor wartenCursor
= new Cursor(Cursor
.WAIT_CURSOR
);
66 public final Cursor normalCursor
= new Cursor(Cursor
.DEFAULT_CURSOR
);
68 public static String dbIpAndName
= "jdbc:mysql://192.168.2.3:3306/rtadaten";
69 public static String dbUser
= "rtauser";
70 public static String dbPassword
= "rtacurie";
71 public static String officeProgrammPfad
= "C:/Programme/OpenOffice.org 3";
72 public static String officeNativePfad
= "C:/RehaVerwaltung/Libraries/lib/openofficeorg/";
73 public static String progHome
= "C:/RehaVerwaltung/";
74 public static String aktIK
= "510841109";
75 public static String hmRechnungPrivat
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
76 public static String hmRechnungKasse
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
77 public static String rhRechnungPrivat
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
78 public static String rhRechnungKasse
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
80 public static String dbIpAndName = "jdbc:mysql://192.168.2.2:3306/rtadaten";
81 public static String dbUser = "rtauser";
82 public static String dbPassword = "rtacurie";
83 public static String officeProgrammPfad = "C:/Programme/OpenOffice.org 3";
84 public static String officeNativePfad = "C:/RehaVerwaltung/Libraries/lib/openofficeorg/";
85 public static String progHome = "C:/RehaVerwaltung/";
86 public static String aktIK = "510841109";
87 public static String hmRechnungPrivat = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
88 public static String hmRechnungKasse = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
89 public static String rhRechnungPrivat = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
90 public static String rhRechnungKasse = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
92 public static boolean testcase
= false;
94 public static int xport
= -1;
95 public static boolean xportOk
= false;
96 public RehaReverseServer rehaReverseServer
= null;
97 public static int rehaReversePort
= -1;
98 public boolean isLibreOffice
;
99 SqlInfo sqlInfo
= null;
101 public static void main(String
[] args
) {
102 RehaSql application
= new RehaSql();
103 application
.getInstance();
104 application
.getInstance().sqlInfo
= new SqlInfo();
105 if(args
.length
> 0 || testcase
){
107 System
.out
.println("hole daten aus INI-Datei "+args
[0]);
108 INIFile inif
= new INIFile(args
[0]+"ini/"+args
[1]+"/rehajava.ini");
109 dbIpAndName
= inif
.getStringProperty("DatenBank","DBKontakt1");
110 dbUser
= inif
.getStringProperty("DatenBank","DBBenutzer1");
111 String pw
= inif
.getStringProperty("DatenBank","DBPasswort1");
112 String decrypted
= null;
114 Verschluesseln man
= Verschluesseln
.getInstance();
115 man
.init(Verschluesseln
.getPassword().toCharArray(), man
.getSalt(), man
.getIterations());
116 decrypted
= man
.decrypt (pw
);
118 decrypted
= new String("");
120 dbPassword
= decrypted
.toString();
121 inif
= new INIFile(args
[0]+"ini/"+args
[1]+"/rehajava.ini");
122 officeProgrammPfad
= inif
.getStringProperty("OpenOffice.org","OfficePfad");
123 officeNativePfad
= inif
.getStringProperty("OpenOffice.org","OfficeNativePfad");
126 INITool
.init(progHome
+"ini/"+aktIK
+"/");
127 if(args
.length
>= 3){
128 rehaReversePort
= Integer
.parseInt(args
[2]);
132 final RehaSql xapplication
= application
;
133 new SwingWorker
<Void
,Void
>(){
135 protected Void
doInBackground() throws java
.lang
.Exception
{
136 xapplication
.starteDB();
137 long zeit
= System
.currentTimeMillis();
141 if(System
.currentTimeMillis()-zeit
> 10000){
144 } catch (InterruptedException e
) {
149 JOptionPane
.showMessageDialog(null, "Datenbank konnte nicht geöffnet werden!\nReha-Sql kann nicht gestartet werden");
151 RehaSql
.starteOfficeApplication();
156 application
.getJFrame();
159 final RehaSql xapplication = application;
160 new SwingWorker<Void,Void>(){
162 protected Void doInBackground() throws java.lang.Exception {
163 xapplication.starteDB();
164 long zeit = System.currentTimeMillis();
168 if(System.currentTimeMillis()-zeit > 5000){
171 } catch (InterruptedException e) {
176 JOptionPane.showMessageDialog(null, "Datenbank konnte nicht geöffnet werden!\nReha-Sql kann nicht gestartet werden");
178 RehaSql.starteOfficeApplication();
183 application.getJFrame();
186 JOptionPane
.showMessageDialog(null, "Keine Datenbankparameter übergeben!\nReha-Sql kann nicht gestartet werden");
192 /********************/
194 public JFrame
getJFrame(){
196 UIManager
.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
197 } catch (ClassNotFoundException e
) {
199 } catch (InstantiationException e
) {
201 } catch (IllegalAccessException e
) {
203 } catch (UnsupportedLookAndFeelException e
) {
207 jFrame
= new JFrame(){
212 private static final long serialVersionUID
= 1L;
215 public void setVisible(final boolean visible
) {
217 if(getState()!=JFrame
.NORMAL
) { setState(JFrame
.NORMAL
); }
220 //setDisposed(false);
222 if (!visible
|| !isVisible()) {
223 super.setVisible(visible
);
227 int state
= super.getExtendedState();
228 state
&= ~JFrame
.ICONIFIED
;
229 super.setExtendedState(state
);
230 super.setAlwaysOnTop(true);
232 super.requestFocus();
233 super.setAlwaysOnTop(false);
238 public void toFront() {
239 super.setVisible(true);
240 int state
= super.getExtendedState();
241 state
&= ~JFrame
.ICONIFIED
;
242 super.setExtendedState(state
);
243 super.setAlwaysOnTop(true);
245 super.requestFocus();
246 super.setAlwaysOnTop(false);
250 rehaReverseServer
= new RehaReverseServer(7000);
251 }catch(Exception ex
){
252 rehaReverseServer
= null;
254 sqlInfo
.setFrame(jFrame
);
255 jFrame
.addWindowListener(this);
256 jFrame
.setSize(1000,700);
257 jFrame
.setTitle("Thera-Pi Sql-Modul [IK: "+aktIK
+"] "+"[Server-IP: "+dbIpAndName
+"] - Äußerste Vorsicht ist geboten!!!");
258 jFrame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
259 jFrame
.setLocationRelativeTo(null);
260 jFrame
.getContentPane().add (new RehaSqlTab());
261 jFrame
.setVisible(true);
264 new SocketClient().setzeRehaNachricht(RehaSql
.rehaReversePort
,"AppName#RehaSql#"+Integer
.toString(RehaSql
.xport
));
265 new SocketClient().setzeRehaNachricht(RehaSql
.rehaReversePort
,"RehaSql#"+RehaIOMessages
.IS_STARTET
);
266 }catch(Exception ex
){
267 JOptionPane
.showMessageDialog(null, "Fehler in der Socketkommunikation");
274 /********************/
276 public RehaSql
getInstance(){
281 /*******************/
283 public void starteDB(){
285 //piHelpDatenbankStarten dbstart = new piHelpDatenbankStarten();
288 DatenbankStarten dbstart
= new DatenbankStarten();
293 /*******************/
295 public static void stoppeDB(){
297 RehaSql
.thisClass
.conn
.close();
298 RehaSql
.thisClass
.conn
= null;
299 } catch (SQLException e
) {
304 /**********************************************************
307 final class DatenbankStarten
implements Runnable
{
308 private void StarteDB(){
309 final RehaSql obj
= RehaSql
.thisClass
;
311 final String sDB
= "SQL";
312 if (obj
.conn
!= null){
315 catch(final SQLException e
){}
318 Class
.forName("com.mysql.jdbc.Driver").newInstance();
319 } catch (InstantiationException e
) {
321 System
.out
.println(sDB
+"Treiberfehler: " + e
.getMessage());
322 RehaSql
.DbOk
= false;
324 } catch (IllegalAccessException e
) {
326 System
.out
.println(sDB
+"Treiberfehler: " + e
.getMessage());
327 RehaSql
.DbOk
= false;
329 } catch (ClassNotFoundException e
) {
331 System
.out
.println(sDB
+"Treiberfehler: " + e
.getMessage());
332 RehaSql
.DbOk
= false;
336 obj
.conn
= (Connection
) DriverManager
.getConnection(dbIpAndName
+"?jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull",dbUser
,dbPassword
);
337 RehaSql
.thisClass
.sqlInfo
.setConnection(obj
.conn
);
339 System
.out
.println("Datenbankkontakt hergestellt");
341 catch (final SQLException ex
) {
342 System
.out
.println("SQLException: " + ex
.getMessage());
343 System
.out
.println("SQLState: " + ex
.getSQLState());
344 System
.out
.println("VendorError: " + ex
.getErrorCode());
345 RehaSql
.DbOk
= false;
356 /*****************************************************************
359 /**********************************************************
362 final class piHelpDatenbankStarten
implements Runnable
{
366 private void StarteDB(){
367 final RehaSql obj
= RehaSql
.thisClass
;
369 final String sDB
= "SQL";
370 if (obj
.conn
!= null){
373 catch(final SQLException e
){}
376 Class
.forName("de.root1.jpmdbc.Driver");
377 //Class.forName("com.mysql.jdbc.Driver").newInstance();
379 } catch (ClassNotFoundException e
) {
381 JOptionPane
.showMessageDialog(null, "Kein Kontakt zu MySql bei 1 & 1");
382 System
.out
.println(sDB
+"Treiberfehler: " + e
.getMessage());
383 RehaSql
.DbOk
= false;
387 System
.out
.println("Starte de.root1.jpmdbc.Drive");
388 //System.out.println("Starte Serveradresse:192.168.2.2");
389 //obj.connMySql = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.2.2:3306/dbf","entwickler","entwickler");
390 Properties connProperties
= new Properties();
391 connProperties
.setProperty("user", "dbo336243054");
392 connProperties
.setProperty("password", "allepreise");
393 //connProperties.setProperty("host", "localhost");
394 connProperties
.setProperty("host", "db2614.1und1.de");
395 //connProperties.setProperty("host", "db2614.1und1.de");
396 connProperties
.setProperty("port", "3306");
397 connProperties
.setProperty("compression","false");
398 connProperties
.setProperty("NO_DRIVER_INFO", "1");
400 obj
.conn
= (Connection
) DriverManager
.getConnection("jdbc:jpmdbc:http://www.thera-pi.org/jpmdbc.php?db336243054",connProperties
);
402 //obj.conn = (Connection) DriverManager.getConnection(dbIpAndName,dbUser,dbPassword);
405 System
.out
.println("Datenbankkontakt hergestellt");
407 catch (final SQLException ex
) {
408 JOptionPane
.showMessageDialog(null, "Kein Kontakt zu MySql bei 1 & 1");
409 System
.out
.println("SQLException: " + ex
.getMessage());
410 System
.out
.println("SQLState: " + ex
.getSQLState());
411 System
.out
.println("VendorError: " + ex
.getErrorCode());
412 RehaSql
.DbOk
= false;
424 public void windowActivated(WindowEvent arg0
) {
427 public void windowClosed(WindowEvent arg0
) {
428 if(RehaSql
.thisClass
.conn
!= null){
430 RehaSql
.thisClass
.conn
.close();
431 System
.out
.println("Datenbankverbindung wurde geschlossen");
432 } catch (SQLException e
) {
439 public void windowClosing(WindowEvent arg0
) {
440 if(RehaSql
.thisClass
.conn
!= null){
442 RehaSql
.thisClass
.conn
.close();
443 System
.out
.println("Datenbankverbindung wurde geschlossen");
444 } catch (SQLException e
) {
448 if(RehaSql
.thisClass
.rehaReverseServer
!= null){
450 new SocketClient().setzeRehaNachricht(RehaSql
.rehaReversePort
,"RehaSql#"+RehaIOMessages
.IS_FINISHED
);
451 rehaReverseServer
.serv
.close();
452 }catch(Exception ex
){
453 ex
.printStackTrace();
460 public void windowDeactivated(WindowEvent arg0
) {
463 public void windowDeiconified(WindowEvent arg0
) {
466 public void windowIconified(WindowEvent arg0
) {
469 public void windowOpened(WindowEvent arg0
) {
472 /***************************/
474 public static void starteOfficeApplication(){
476 officeapplication
= (IOfficeApplication
)new StartOOApplication(RehaSql
.officeProgrammPfad
,RehaSql
.officeNativePfad
).start(false);
477 System
.out
.println("OpenOffice ist gestartet und Active ="+officeapplication
.isActive());
478 } catch (OfficeApplicationException e1
) {
479 e1
.printStackTrace();