Home > Domino Tips > Developer > Java > How to resolve the problem of planning in Lotus Notes
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

How to resolve the problem of planning in Lotus Notes


Thierry Brouard
07.17.2001
Rating: -3.50- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This program is an Applet. It is used to draw a planning of room reservations for a defined day.

This Applet is not optimized. It has just a dimension instructive. This Applet uses the result of requests as well as the parameters of a mask "fiches" and also a view "resources." It is a French application but I have internationalized this version. The mask transmits like parameters to the Applet with the fields "day" and "scale." The "resources" view is only used to know the list of the rooms to display.

To use it, compile this code with your Java compiler, create a new form "fiches." If you prefer another name, no problem, but don't forget to modify your code. Create an Applet object in this form and include these files, *.class, made by your Java compiler inside your Applet Objet. You can also update this program to manage human resources in a project.



Code

*/

import lotus.domino.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.applet.Applet;
import java.util.Vector;

public class Planning extends AppletBase {
   Session s = null;
   Database db = null;
   View vw = null;
   DocumentCollection dc = null;
   int debug = 0;

   Vector resa = new Vector();
   String paramDay;
   String[] room;
   int nbr_rooms;
   int appWidth = 0;
   int appHeight = 0;
   int timestart = 0;
   int timeend = 0;

   public void notesAppletInit() {
      paramDay = getParameter("paramDay");
      String paramScale = getParameter("paramScale");
      switch (Integer.parseInt(paramScale)) {
      case 1: timestart = 0; timeend = 24; break;
      case 2: timestart = 6; timeend = 22; break;
      case 3: timestart = 8; timeend = 20; break;
      }
      setLayout(null);
      appWidth = getSize().width;
      appHeight = getSize().height;
      if (debug!=0) System.out.println( "paramDay = " + paramDay + "nparamScale = " + paramScale + "ntaille = " + appHeight + "H x " + appWidth + "L" );
      
   }

   public void notesAppletStart() {
      int i;

      try {
         getDatabaseConnection();
      } catch(Exception e) {
         System.err.println("Error AppletStart. "+e);
      }
      try {
         ViewEntryCollection vec;
         try {
            vec = vw.getAllEntries();
            nbr_rooms = vec.getCount();
            if (debug!=0) System.out.println( "Nombre de rooms trouvees : " + nbr_rooms );
            room = new String[nbr_rooms];
         } catch(NotesException ne) {
            System.err.println("Echec lors de la recuperation des entrees. "+ne);
            throw ne;
         }
         if (debug!=0) System.out.println( "Recuperation des dates." );
         Document doc;
         for( i=0; i<nbr_rooms; i++ ) {
            doc = vw.getNthDocument(i+1);
            room[i] = doc.getItemValueString("room");

            if (debug!=0) System.out.println( room[i] + " -> " );
            try {
               String formula = "form="fiches" & paramDay=["+paramDay+"] & room=""+room[i]+""";
               dc = db.search(formula);
               int matches = dc.getCount();
               if (debug!=0) System.out.println( formula + " ok " + matches + " resultats." );
              
              Document searchdoc = dc.getFirstDocument();
              while (searchdoc != null) {
                 Vector ddeb = searchdoc.getItemValue("hour_s");
                 Vector dfin = searchdoc.getItemValue("hour_e");
                 DateTime dt1 = (DateTime)ddeb.elementAt(0);
                 DateTime dt2 = (DateTime)dfin.elementAt(0);
                 resa.addElement(new Reservations(i,dt1,dt2));
                 searchdoc = dc.getNextDocument(); 
              }

            } catch(NotesException ne) {
               System.err.println("err "+ne);
               throw ne;
            }
         }

       } catch(Exception e) {
          System.err.println("Echec lors du dessin composant. "+e);
      }
   }

   private Database getDatabaseConnection() throws Exception {
      if(s==null) {
         s = this.getSession();
         if (s == null) {
            throw new Exception("Impossible d'obtenir la session notes.");
         } else {
            if (debug!=0) System.out.println("Recuperation de la session reussie");
         }
      }
      if(db==null) {
         try {
            NotesAppletContext ap = getContext(s);
            db = ap.getDatabase();
            if (db == null) {
               throw new Exception("Impossible d'obtenir le db.");
            } 	
            if (debug!=0) System.out.println("Connection reussie");
         } catch(Exception e) {
            System.err.println("Echec de connection. "+e);
            e.printStackTrace(System.err);
         }
      }
      if(vw==null) {
         try {
            vw = db.getView("Ressources");
            if (vw == null) {
               throw new Exception("Impossible de recuperer la vue.");
            } else {
               if (debug!=0) System.out.println("Recuperation de la vue reussie");
            }
         } catch(NotesException ne) {
            System.err.println("Echec lors de l'initialisation de la vue. "+ne);
            throw ne;
          }
      }
      return db;
   }

   public void notesAppletStop() {
      if(db!=null) {
         try {
            db.recycle();
            s.recycle();         
         } catch(Exception e) {
            System.err.println("Echec lors de la fermeture de la connection. "+e);
            e.printStackTrace();
         } finally {
            s = null;
            db = null;
         }
      }
   }

   public String getAppletInfo() {
      return "Planning Thierry B. (10/7/2001)";
   }

   public void update(Graphics g) {
      paint(g);
   }

   public void paint( Graphics g ) {      
      super.paint(g);
      if (debug!=0) System.out.println("paint");

      int x_offset;
      int y_offset;
      int nbr_hours;
      int left_margin = 80;
      int top_margin = 40;
      double x_pos;
      int y_pos;
      double l_pos;
      int i;
      String t;
  
      try {

         nbr_hours = timeend-timestart;
         x_offset = (appWidth-left_margin)/nbr_hours;
         y_offset = 40;

         // I draw the background.

         g.setColor(Color.black);
         g.drawLine(0,20,appWidth,20);
         g.drawLine(left_margin,0,left_margin,(nbr_rooms*y_offset)+20);

         for( i=0; i<nbr_hours; i++ ) {
            x_pos = left_margin+(i*x_offset);
            if (i!=0) 
               g.setColor(Color.lightGray);
               g.drawLine((int)x_pos,10,(int)x_pos,(nbr_rooms*y_offset)+20);
	    t = String.valueOf(timestart+i)+"h";
            g.setColor(Color.black);
            g.drawString(t,(int)x_pos+5,10);
         }
         for( i=0; i<nbr_rooms; i++ ) {
            y_pos = top_margin+(i*y_offset);
            g.setColor(Color.red);
            g.drawString(room[i],0,y_pos+5);
            g.setColor(Color.black);
            g.drawLine(0,y_pos+20,appWidth,y_pos+20);    
         }

         // I draw the planning.
         int np = resa.size();
         for( i=0; i<np; i++ ) {
            Reservations r = (Reservations)resa.elementAt(i);
            SimpleDateFormat fmt = new SimpleDateFormat("HHmm");
            int dd = Integer.parseInt(fmt.format(r.datestart.toJavaDate()));
            int df = Integer.parseInt(fmt.format(r.dateend.toJavaDate()));
            int diff = (df-dd);
	    y_pos = top_margin+(r.indice*y_offset)-10;
            x_pos = left_margin+(double)((dd/100)*x_offset)-(timestart*x_offset);
            l_pos = (double)((diff/100)*x_offset);

            g.setColor(Color.orange);
            g.fillRect((int)x_pos,y_pos,(int)l_pos,20);
            g.setColor(Color.black);
            g.drawRect((int)x_pos,y_pos,(int)l_pos,20);
         }

      } catch(Exception e) {
         System.err.println("Traitement de chaine errone");
         e.printStackTrace();
      }
   }
}

class Reservations {
   int indice;
   DateTime datestart;
   DateTime dateend;

   public Reservations(int ind,DateTime dd,DateTime df) {
      indice = ind;
      datestart = dd;
      dateend = df;
   }
}

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Java
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts