7 import java
.awt
.Cursor
;
8 import java
.awt
.Toolkit
;
9 import java
.awt
.event
.WindowEvent
;
10 import java
.awt
.event
.WindowListener
;
11 import java
.io
.IOException
;
12 import java
.sql
.Connection
;
13 import java
.sql
.DriverManager
;
14 import java
.sql
.SQLException
;
15 import java
.util
.Properties
;
17 import javax
.swing
.JFrame
;
18 import javax
.swing
.JOptionPane
;
19 import javax
.swing
.UIManager
;
20 import javax
.swing
.UnsupportedLookAndFeelException
;
22 import org
.jdesktop
.swingworker
.SwingWorker
;
24 import reha301Panels
.RehaIOMessages
;
25 import CommonTools
.INIFile
;
26 import CommonTools
.SqlInfo
;
27 import CommonTools
.StartOOApplication
;
28 import CommonTools
.Verschluesseln
;
29 import ag
.ion
.bion
.officelayer
.application
.IOfficeApplication
;
30 import ag
.ion
.bion
.officelayer
.application
.OfficeApplicationException
;
32 public class Reha301
implements WindowListener
{
33 public static boolean DbOk
;
35 public static JFrame thisFrame
= null;
36 public Connection conn
;
37 public static Reha301 thisClass
;
39 public static IOfficeApplication officeapplication
;
41 public String dieseMaschine
= null;
43 public static String dbIpAndName = null;
44 public static String dbUser = null;
45 public static String dbPassword = null;
48 public final Cursor wartenCursor
= new Cursor(Cursor
.WAIT_CURSOR
);
49 public final Cursor normalCursor
= new Cursor(Cursor
.DEFAULT_CURSOR
);
50 public final Cursor kreuzCursor
= new Cursor(Cursor
.CROSSHAIR_CURSOR
);
51 public final Cursor cmove
= new Cursor(Cursor
.MOVE_CURSOR
); // @jve:decl-index=0:
52 public final Cursor cnsize
= new Cursor(Cursor
.N_RESIZE_CURSOR
); // @jve:decl-index=0:
53 public final Cursor cnwsize
= new Cursor(Cursor
.NW_RESIZE_CURSOR
); // @jve:decl-index=0:
54 public final Cursor cnesize
= new Cursor(Cursor
.NE_RESIZE_CURSOR
); // @jve:decl-index=0:
55 public final Cursor cswsize
= new Cursor(Cursor
.SW_RESIZE_CURSOR
); // @jve:decl-index=0:
56 public final Cursor cwsize
= new Cursor(Cursor
.W_RESIZE_CURSOR
); // @jve:decl-index=0:
57 public final Cursor csesize
= new Cursor(Cursor
.SE_RESIZE_CURSOR
); // @jve:decl-index=0:
58 public final Cursor cssize
= new Cursor(Cursor
.S_RESIZE_CURSOR
); // @jve:decl-index=0:
59 public final Cursor cesize
= new Cursor(Cursor
.E_RESIZE_CURSOR
); // @jve:decl-index=0:
60 public final Cursor cdefault
= new Cursor(Cursor
.DEFAULT_CURSOR
); // @jve:decl-index=0:
63 public static String dbIpAndName
= "jdbc:mysql://192.168.2.2:3306/rtadaten";
64 public static String dbUser
= "rtauser";
65 public static String dbPassword
= "rtacurie";
66 public static String officeProgrammPfad
= "C:/Program Files (x86)/LibreOffice 3";
67 //public static String officeProgrammPfad = "C:/Programme/OpenOffice.org 3";
68 public static String officeNativePfad
= "C:/RehaVerwaltung/Libraries/lib/openofficeorg/";
69 public static String progHome
= "C:/RehaVerwaltung/";
70 public static String aktIK
= "510841109";
71 public static String hmRechnungPrivat
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
72 public static String hmRechnungKasse
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
73 public static String rhRechnungPrivat
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
74 public static String rhRechnungKasse
= "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
76 public static boolean nachrichtfuerRezept
= false;
77 public static String argsRezeptnummer
= "";
79 public static String inbox
= "//192.168.2.3/programme/data301/540840108/inbox/"; //C:/OODokumente/RehaVerwaltung/Dokumentation/301-er/";
80 public static String outbox
="//192.168.2.3/programme/data301/540840108/outbox/";
82 public static int rehaPort
= -1;
84 public static int xport
= 7000;
85 public static boolean xportOk
= false;
86 public RehaReverseServer rehaReverseServer
= null;
88 public boolean isLibreOffice
;
90 public SqlInfo sqlInfo
= null;
92 //public static String encodepfad = "C:/OODokumente/RehaVerwaltung/Dokumentation/301-er/";
94 public static String dbIpAndName = "jdbc:mysql://192.168.2.2:3306/rtadaten";
95 public static String dbUser = "rtauser";
96 public static String dbPassword = "rtacurie";
97 public static String officeProgrammPfad = "C:/Programme/OpenOffice.org 3";
98 public static String officeNativePfad = "C:/RehaVerwaltung/Libraries/lib/openofficeorg/";
99 public static String progHome = "C:/RehaVerwaltung/";
100 public static String aktIK = "510841109";
101 public static String hmRechnungPrivat = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
102 public static String hmRechnungKasse = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
103 public static String rhRechnungPrivat = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
104 public static String rhRechnungKasse = "C:/RehaVerwaltung/vorlagen/HMRechnungPrivatKopie.ott";
106 public static boolean testcase
= false;
108 public static void main(String
[] args
) {
109 Reha301 application
= new Reha301();
110 application
.getInstance();
111 application
.getInstance().sqlInfo
= new SqlInfo();
112 if(args
.length
> 0 || testcase
){
114 //System.out.println("hole daten aus INI-Datei "+args[0]);
115 INIFile inif
= new INIFile(args
[0]+"ini/"+args
[1]+"/rehajava.ini");
116 dbIpAndName
= inif
.getStringProperty("DatenBank","DBKontakt1");
117 dbUser
= inif
.getStringProperty("DatenBank","DBBenutzer1");
118 String pw
= inif
.getStringProperty("DatenBank","DBPasswort1");
119 String decrypted
= null;
121 Verschluesseln man
= Verschluesseln
.getInstance();
122 man
.init(Verschluesseln
.getPassword().toCharArray(), man
.getSalt(), man
.getIterations());
123 decrypted
= man
.decrypt (pw
);
125 decrypted
= new String("");
127 dbPassword
= decrypted
.toString();
128 inif
= new INIFile(args
[0]+"ini/"+args
[1]+"/rehajava.ini");
129 officeProgrammPfad
= inif
.getStringProperty("OpenOffice.org","OfficePfad");
130 officeNativePfad
= inif
.getStringProperty("OpenOffice.org","OfficeNativePfad");
133 INIFile ini301
= new INIFile(args
[0]+"ini/"+args
[1]+"/dta301.ini");
134 inbox
= ini301
.getStringProperty("DatenPfade301", "inbox");
135 outbox
= ini301
.getStringProperty("DatenPfade301", "outbox");
136 if(args
.length
== 3){
138 rehaPort
= Integer
.parseInt(args
[2]);
140 //new SocketClient().setzeRehaNachricht(rehaPort, "Reha301#IrgendEineNachricht");
141 //JOptionPane.showMessageDialog(null, "Modul Reha301 registriert Port "+Integer.toString(rehaPort));
142 }catch(Exception ex
){
143 JOptionPane
.showMessageDialog(null, "Fehler im Modul Reha301, kann den IO-Port nicht ermitteln");
147 final Reha301 xapplication
= application
;
148 new SwingWorker
<Void
,Void
>(){
150 protected Void
doInBackground() throws java
.lang
.Exception
{
151 xapplication
.starteDB();
152 long zeit
= System
.currentTimeMillis();
156 if(System
.currentTimeMillis()-zeit
> 10000){
159 } catch (InterruptedException e
) {
164 JOptionPane
.showMessageDialog(null, "Datenbank konnte nicht geöffnet werden!\nReha-301 kann nicht gestartet werden");
166 Reha301
.starteOfficeApplication();
172 application
.getJFrame();
173 new SocketClient().setzeRehaNachricht(rehaPort
, "Reha301#"+RehaIOMessages
.IS_STARTET
);
176 } catch (InterruptedException e
) {
179 //new SocketClient().setzeRehaNachricht(rehaPort, "Reha301#"+RehaIOMessages.MUST_PATANDREZFIND+"#28222#RH7194");
182 final Reha301 xapplication = application;
183 new SwingWorker<Void,Void>(){
185 protected Void doInBackground() throws java.lang.Exception {
186 xapplication.starteDB();
187 long zeit = System.currentTimeMillis();
191 if(System.currentTimeMillis()-zeit > 5000){
194 } catch (InterruptedException e) {
199 JOptionPane.showMessageDialog(null, "Datenbank konnte nicht ge�ffnet werden!\nReha-Sql kann nicht gestartet werden");
201 Reha301.starteOfficeApplication();
206 application.getJFrame();
209 JOptionPane
.showMessageDialog(null, "Keine Datenbankparameter übergeben!\nReha-Sql kann nicht gestartet werden");
216 /********************/
218 public JFrame
getJFrame(){
220 UIManager
.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
221 } catch (ClassNotFoundException e
) {
223 } catch (InstantiationException e
) {
225 } catch (IllegalAccessException e
) {
227 } catch (UnsupportedLookAndFeelException e
) {
231 jFrame
= new JFrame(){
236 private static final long serialVersionUID
= 1L;
239 public void setVisible(final boolean visible
) {
241 if(getState()!=JFrame
.NORMAL
) { setState(JFrame
.NORMAL
); }
244 //setDisposed(false);
246 if (!visible
|| !isVisible()) {
247 super.setVisible(visible
);
251 int state
= super.getExtendedState();
252 state
&= ~JFrame
.ICONIFIED
;
253 super.setExtendedState(state
);
254 super.setAlwaysOnTop(true);
256 super.requestFocus();
257 super.setAlwaysOnTop(false);
262 public void toFront() {
263 super.setVisible(true);
264 int state
= super.getExtendedState();
265 state
&= ~JFrame
.ICONIFIED
;
266 super.setExtendedState(state
);
267 super.setAlwaysOnTop(true);
269 super.requestFocus();
270 super.setAlwaysOnTop(false);
273 sqlInfo
.setFrame(jFrame
);
274 jFrame
.addWindowListener(this);
275 jFrame
.setSize(1000,550);
276 jFrame
.setTitle("Thera-Pi §301-er [IK: "+aktIK
+"] "+"[Server-IP: "+dbIpAndName
+"]");
277 jFrame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
278 jFrame
.setLocationRelativeTo(null);
279 jFrame
.getContentPane().add (new Reha301Tab());
280 jFrame
.setIconImage( Toolkit
.getDefaultToolkit().getImage( Reha301
.progHome
+"icons/abr301.png" ) );
281 jFrame
.setVisible(true);
283 new SwingWorker
<Void
,Void
>(){
285 protected Void
doInBackground() throws Exception
{
287 while( Reha301
.xport
< 7050 && Reha301
.xportOk
== false){
290 rehaReverseServer
= new RehaReverseServer(Reha301
.xport
);
291 } catch (InterruptedException e
) {
296 new SocketClient().setzeRehaNachricht(rehaPort
, "AppName#"+"Reha301#"+Integer
.toString(Reha301
.xport
));
298 //System.out.println(Reha301.xport+" - "+Reha301.xportOk);
300 }catch(Exception ex
){
301 ex
.printStackTrace();
312 /********************/
314 public Reha301
getInstance(){
319 /*******************/
321 public void starteDB(){
323 //piHelpDatenbankStarten dbstart = new piHelpDatenbankStarten();
326 DatenbankStarten dbstart
= new DatenbankStarten();
331 /*******************/
333 public static void stoppeDB(){
335 Reha301
.thisClass
.conn
.close();
336 Reha301
.thisClass
.conn
= null;
337 } catch (SQLException e
) {
342 /**********************************************************
345 final class DatenbankStarten
implements Runnable
{
346 private void StarteDB(){
347 final Reha301 obj
= Reha301
.thisClass
;
349 //final String sDB = "SQL";
350 if (obj
.conn
!= null){
353 catch(final SQLException e
){}
356 Class
.forName("com.mysql.jdbc.Driver").newInstance();
357 } catch (InstantiationException e
) {
359 //System.out.println(sDB+"Treiberfehler: " + e.getMessage());
360 Reha301
.DbOk
= false;
362 } catch (IllegalAccessException e
) {
364 //System.out.println(sDB+"Treiberfehler: " + e.getMessage());
365 Reha301
.DbOk
= false;
367 } catch (ClassNotFoundException e
) {
369 //System.out.println(sDB+"Treiberfehler: " + e.getMessage());
370 Reha301
.DbOk
= false;
375 obj
.conn
= (Connection
) DriverManager
.getConnection(dbIpAndName
+"?jdbcCompliantTruncation=false",dbUser
,dbPassword
);
376 Reha301
.thisClass
.sqlInfo
.setConnection(obj
.conn
);
379 catch (final SQLException ex
) {
380 //System.out.println("SQLException: " + ex.getMessage());
381 //System.out.println("SQLState: " + ex.getSQLState());
382 //System.out.println("VendorError: " + ex.getErrorCode());
383 Reha301
.DbOk
= false;
394 /*****************************************************************
397 /**********************************************************
402 public void windowActivated(WindowEvent arg0
) {
405 public void windowClosed(WindowEvent arg0
) {
406 if(Reha301
.thisClass
.conn
!= null){
408 Reha301
.thisClass
.conn
.close();
409 //System.out.println("Datenbankverbindung wurde geschlossen");
410 } catch (SQLException e
) {
414 if(rehaReverseServer
!= null){
416 rehaReverseServer
.serv
.close();
417 //System.out.println("RehaIO-SocketServer geschlossen");
418 } catch (IOException e
) {
425 public void windowClosing(WindowEvent arg0
) {
426 if(Reha301
.thisClass
.conn
!= null){
428 Reha301
.thisClass
.conn
.close();
429 //System.out.println("Datenbankverbindung wurde geschlossen");
430 new SocketClient().setzeRehaNachricht(rehaPort
, "Reha301#"+RehaIOMessages
.IS_FINISHED
);
431 } catch (SQLException e
) {
435 if(rehaReverseServer
!= null){
437 rehaReverseServer
.serv
.close();
438 //System.out.println("RehaIO-SocketServer geschlossen");
439 } catch (IOException e
) {
447 public void windowDeactivated(WindowEvent arg0
) {
450 public void windowDeiconified(WindowEvent arg0
) {
453 public void windowIconified(WindowEvent arg0
) {
456 public void windowOpened(WindowEvent arg0
) {
459 /***************************/
461 public static void starteOfficeApplication(){
465 officeapplication
= (IOfficeApplication
)new StartOOApplication(Reha301
.officeProgrammPfad
,Reha301
.officeNativePfad
).start(false);
466 System
.out
.println("OpenOffice ist gestartet und Active ="+officeapplication
.isActive());
467 }catch (OfficeApplicationException e
) {