*** empty log message ***
[thera-pi.git] / Reha301 / src / reha301 / Reha301.java
blob74e386da7b5a102720f53154d6ab08db0d6476b0
1 package reha301;
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;
34 JFrame jFrame;
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){
113 if(!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;
120 if(pw != null){
121 Verschluesseln man = Verschluesseln.getInstance();
122 man.init(Verschluesseln.getPassword().toCharArray(), man.getSalt(), man.getIterations());
123 decrypted = man.decrypt (pw);
124 }else{
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");
131 progHome = args[0];
132 aktIK = args[1];
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){
137 try{
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>(){
149 @Override
150 protected Void doInBackground() throws java.lang.Exception {
151 xapplication.starteDB();
152 long zeit = System.currentTimeMillis();
153 while(! DbOk){
154 try {
155 Thread.sleep(20);
156 if(System.currentTimeMillis()-zeit > 10000){
157 System.exit(0);
159 } catch (InterruptedException e) {
160 e.printStackTrace();
163 if(!DbOk){
164 JOptionPane.showMessageDialog(null, "Datenbank konnte nicht geöffnet werden!\nReha-301 kann nicht gestartet werden");
166 Reha301.starteOfficeApplication();
168 return null;
171 }.execute();
172 application.getJFrame();
173 new SocketClient().setzeRehaNachricht(rehaPort, "Reha301#"+RehaIOMessages.IS_STARTET);
174 try {
175 Thread.sleep(100);
176 } catch (InterruptedException e) {
177 e.printStackTrace();
179 //new SocketClient().setzeRehaNachricht(rehaPort, "Reha301#"+RehaIOMessages.MUST_PATANDREZFIND+"#28222#RH7194");
180 }else{
182 final Reha301 xapplication = application;
183 new SwingWorker<Void,Void>(){
184 @Override
185 protected Void doInBackground() throws java.lang.Exception {
186 xapplication.starteDB();
187 long zeit = System.currentTimeMillis();
188 while(! DbOk){
189 try {
190 Thread.sleep(20);
191 if(System.currentTimeMillis()-zeit > 5000){
192 System.exit(0);
194 } catch (InterruptedException e) {
195 e.printStackTrace();
198 if(!DbOk){
199 JOptionPane.showMessageDialog(null, "Datenbank konnte nicht ge�ffnet werden!\nReha-Sql kann nicht gestartet werden");
201 Reha301.starteOfficeApplication();
202 return null;
205 }.execute();
206 application.getJFrame();
209 JOptionPane.showMessageDialog(null, "Keine Datenbankparameter übergeben!\nReha-Sql kann nicht gestartet werden");
210 System.exit(0);
216 /********************/
218 public JFrame getJFrame(){
219 try {
220 UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
221 } catch (ClassNotFoundException e) {
222 e.printStackTrace();
223 } catch (InstantiationException e) {
224 e.printStackTrace();
225 } catch (IllegalAccessException e) {
226 e.printStackTrace();
227 } catch (UnsupportedLookAndFeelException e) {
228 e.printStackTrace();
230 thisClass = this;
231 jFrame = new JFrame(){
236 private static final long serialVersionUID = 1L;
238 @Override
239 public void setVisible(final boolean visible) {
241 if(getState()!=JFrame.NORMAL) { setState(JFrame.NORMAL); }
243 if (visible) {
244 //setDisposed(false);
246 if (!visible || !isVisible()) {
247 super.setVisible(visible);
250 if (visible) {
251 int state = super.getExtendedState();
252 state &= ~JFrame.ICONIFIED;
253 super.setExtendedState(state);
254 super.setAlwaysOnTop(true);
255 super.toFront();
256 super.requestFocus();
257 super.setAlwaysOnTop(false);
261 @Override
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);
268 super.toFront();
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);
282 thisFrame = jFrame;
283 new SwingWorker<Void,Void>(){
284 @Override
285 protected Void doInBackground() throws Exception {
286 try{
287 while( Reha301.xport < 7050 && Reha301.xportOk == false){
288 try {
289 Thread.sleep(50);
290 rehaReverseServer = new RehaReverseServer(Reha301.xport);
291 } catch (InterruptedException e) {
292 e.printStackTrace();
295 if(Reha301.xportOk){
296 new SocketClient().setzeRehaNachricht(rehaPort, "AppName#"+"Reha301#"+Integer.toString(Reha301.xport));
297 }else{
298 //System.out.println(Reha301.xport+" - "+Reha301.xportOk);
300 }catch(Exception ex){
301 ex.printStackTrace();
303 return null;
306 }.execute();
308 return jFrame;
312 /********************/
314 public Reha301 getInstance(){
315 thisClass = this;
316 return this;
319 /*******************/
321 public void starteDB(){
323 //piHelpDatenbankStarten dbstart = new piHelpDatenbankStarten();
324 //dbstart.run();
326 DatenbankStarten dbstart = new DatenbankStarten();
327 dbstart.run();
331 /*******************/
333 public static void stoppeDB(){
334 try {
335 Reha301.thisClass.conn.close();
336 Reha301.thisClass.conn = null;
337 } catch (SQLException e) {
338 e.printStackTrace();
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){
351 try{
352 obj.conn.close();}
353 catch(final SQLException e){e.printStackTrace();}
355 try{
356 Class.forName("com.mysql.jdbc.Driver").newInstance();
357 } catch (InstantiationException e) {
358 e.printStackTrace();
359 //System.out.println(sDB+"Treiberfehler: " + e.getMessage());
360 Reha301.DbOk = false;
361 return ;
362 } catch (IllegalAccessException e) {
363 e.printStackTrace();
364 //System.out.println(sDB+"Treiberfehler: " + e.getMessage());
365 Reha301.DbOk = false;
366 return ;
367 } catch (ClassNotFoundException e) {
368 e.printStackTrace();
369 //System.out.println(sDB+"Treiberfehler: " + e.getMessage());
370 Reha301.DbOk = false;
371 return ;
373 try {
375 obj.conn = (Connection) DriverManager.getConnection(dbIpAndName+"?jdbcCompliantTruncation=false",dbUser,dbPassword);
376 Reha301.thisClass.sqlInfo.setConnection(obj.conn);
377 Reha301.DbOk = true;
379 catch (final SQLException ex) {
380 ex.printStackTrace();
381 //System.out.println("SQLException: " + ex.getMessage());
382 //System.out.println("SQLState: " + ex.getSQLState());
383 //System.out.println("VendorError: " + ex.getErrorCode());
384 Reha301.DbOk = false;
387 return;
389 public void run() {
390 StarteDB();
395 /*****************************************************************
398 /**********************************************************
402 @Override
403 public void windowActivated(WindowEvent arg0) {
405 @Override
406 public void windowClosed(WindowEvent arg0) {
407 if(Reha301.thisClass.conn != null){
408 try {
409 Reha301.thisClass.conn.close();
410 //System.out.println("Datenbankverbindung wurde geschlossen");
411 } catch (SQLException e) {
412 e.printStackTrace();
415 if(rehaReverseServer != null){
416 try {
417 rehaReverseServer.serv.close();
418 //System.out.println("RehaIO-SocketServer geschlossen");
419 } catch (IOException e) {
420 e.printStackTrace();
423 System.exit(0);
425 @Override
426 public void windowClosing(WindowEvent arg0) {
427 if(Reha301.thisClass.conn != null){
428 try {
429 Reha301.thisClass.conn.close();
430 //System.out.println("Datenbankverbindung wurde geschlossen");
431 new SocketClient().setzeRehaNachricht(rehaPort, "Reha301#"+RehaIOMessages.IS_FINISHED);
432 } catch (SQLException e) {
433 e.printStackTrace();
436 if(rehaReverseServer != null){
437 try {
438 rehaReverseServer.serv.close();
439 //System.out.println("RehaIO-SocketServer geschlossen");
440 } catch (IOException e) {
441 e.printStackTrace();
445 System.exit(0);
447 @Override
448 public void windowDeactivated(WindowEvent arg0) {
450 @Override
451 public void windowDeiconified(WindowEvent arg0) {
453 @Override
454 public void windowIconified(WindowEvent arg0) {
456 @Override
457 public void windowOpened(WindowEvent arg0) {
460 /***************************/
462 public static void starteOfficeApplication(){
466 officeapplication = (IOfficeApplication)new StartOOApplication(Reha301.officeProgrammPfad,Reha301.officeNativePfad).start(false);
467 System.out.println("OpenOffice ist gestartet und Active ="+officeapplication.isActive());
468 }catch (OfficeApplicationException e) {
469 e.printStackTrace();