How to resolve the problem of planning in Lotus Notes

It is used to draw a planning of room reservations for a defined day.

This Content Component encountered an error

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.


*/

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;
   }
}
This was first published in July 2001

Dig deeper on Lotus Notes Domino Administration Tools

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close