Page Index Toggle Pages: [1] 2 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) Jplanner Scheduler java timetable (Read 23643 times)
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Jplanner Scheduler java timetable
Apr 2nd, 2019 at 5:12pm
Print Post  
Hi, I am in pretty urgent need of help to finish my project. I have set out to make a timetable planner for students where the students can add a task to a database and the timetable will take that data and display it to the user. I have managed to do all of this and have used one of the other forum posts to get it to work as a calendar, I have managed to turn it in into a timetable but I amd having problems with:
1) displaying the tasks
2) whatever day is today is repeated twice in the timetable so there are 8 columns.
3) I also want the user to be able to go backward or forward at least one week.

Here is my code:
Code (Java)
Select All
public class revisionPlannerUI extends JFrame {
    public static Calendar calendar = new Calendar();
    public static Task task = new Task();
    ///private AwtCalendar calendar;
    ArrayList<Contact> taskList;
    //Calendar calendar;

    /**
     * Creates new form revisionPlannerUI
     * @throws java.text.ParseException
     */
    public revisionPlannerUI() throws ParseException {
        initComponents();
        calendar.setTheme(ThemeType.Light);
        calendar.setCurrentView(CalendarView.Timetable);
        //calendar.getTimetableSettings().getVisibleColumns();
        Container cp = jPanel2;
        cp.setLayout(new BorderLayout());
        cp.add(calendar, BorderLayout.CENTER);
        for (int i = 0; i < 7; i++) {
            calendar.getTimetableSettings().getDates().add(DateTime.today().addDays(i-1));
            calendar.getTimetableSettings().setItemOffset(30);
            calendar.getTimetableSettings().setShowItemSpans(false);
            calendar.getTimetableSettings().setSnapInterval(Duration.fromMinutes(1));
            calendar.getTimetableSettings().setVisibleColumns(7);
        }
        getTasks();


    }
private void getTasks() throws ParseException{
        try{
            String SQL = "SELECT TASKNAME, TASKDATE, STARTTIME, LENGTH, SUBJECTID FROM TIMETABLE WHERE USERID = '"+globals.dbUserID+"'";
            Connection con = DriverManager.getConnection(globals.host);
            Statement statement = con.createStatement();
            ResultSet resSet = statement.executeQuery(SQL);
            while(resSet.next()){
                Date date = resSet.getDate("TASKDATE");
                Time time = resSet.getTime("STARTTIME");
                int length = resSet.getInt("LENGTH");
                DateTime dt = new DateTime(date.getYear(),date.getMonth(),date.getDay(),time.getHours(),time.getMinutes(),0);
                DateTime dt2 = new DateTime(date.getYear(),date.getMonth(),date.getDay(),time.getHours(),time.getMinutes()+length,0);
                System.out.println(date);
                Style style = new Style();
                style.setBrush(new SolidBrush(new Color(102, 255, 102)));
                DateStyle dStyle = new DateStyle();
                dStyle.setStyle(style);
                dStyle.setFrom(dt);
                dStyle.setTo(dt2);
                task.setName(resSet.getString("TASKNAME"));
                DateTime startDateTime = new DateTime(date);
                task.setStartDate(startDateTime);
                task.setActualDuration(resSet.getInt("LENGTH"));
                task.setId(Integer.toString(resSet.getInt("SUBJECTID")));
                calendar.getTasks().add(task);
                calendar.getDayStyles().add(dStyle);

            }
        }catch(SQLException err){
            System.out.println(err);
        }
    } 



I am in very urgent need of help, your API has already led me to massive progress but I need to over come this last hurdle by tonight. Any help is much appreciated and thanks in advance.
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Jplanner Scheduler java timetable
Reply #1 - Apr 2nd, 2019 at 5:57pm
Print Post  
1) I feel like you want to create Appointment objects instead of Task ones, and add them to the schedule.Items collection. Tasks in our API are kinds of resources displayed as separate columns when you enable grouping in time table, or as rows in resource view, and then appointments could get associated with them.

2) Today is displayed by default. Either skip it when looping over your dates, or remove the first instance.

3) Add some buttons and load new weeks from click handlers?

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #2 - Apr 2nd, 2019 at 11:51pm
Print Post  
Could I get some examples, please? I am on a very tight deadline with other features to program as well.

Very appreciated, Robert
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #3 - Apr 3rd, 2019 at 10:00am
Print Post  
I managed to solve issue no.2
  
Back to top
 
IP Logged
 
Iva_P
YaBB Moderator
*****
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: Jplanner Scheduler java timetable
Reply #4 - Apr 3rd, 2019 at 12:55pm
Print Post  
Hi,
Here is code that connects to MS SQL Server database table called appointments and reads the data for events stored there. It creates MindFusion.Scheduling Appointment instances and renders a weekly calendar with them:

private void readAppointments() throws ClassNotFoundException
{

Connection conn = null;
PreparedStatement pst;

try {
// db parameters

String sql = "SELECT start_time, end_time, header_text, recurrence_interval, description FROM appointments";

String userName = "mindfusion";
String password = "mf1234";

String url = "jdbc:sqlserver://DESKTOP-NV9S0TU\\SQLEXPRESS;databaseName=bookings;";

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, userName, password);

pst = conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
System.out.println(rs.getDate("start_time").toString());
Date start = rs.getDate("start_time");

Date end = rs.getDate("end_time");
String itemText = rs.getString("header_text");
String description = rs.getString("header_text");
int recurrInterval = rs.getInt("recurrence_interval");

Appointment appointment = new Appointment();
appointment.setStartTime(new DateTime(start));
appointment.setEndTime(new DateTime(end));
appointment.setHeaderText(itemText);
appointment.setDescriptionText(description);

calendar.getSchedule().getItems().add(appointment);



}

} catch(SQLException e) {
System.out.println(e.getMessage());
} finally {
try{
if(conn != null)
conn.close();
}catch(SQLException ex){
System.out.println(ex.getMessage());
}
}

}

For your convenience I have taken a screenshot of the DB table with the data:

  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #5 - Apr 3rd, 2019 at 1:47pm
Print Post  
Hi Iva_P,

Thanks for your detailed reply. I have tried to adapt my code to yours using appointments however nothing is still displayed in the time table.

Here is my code:

Code (Java)
Select All
public class revisionPlannerUI extends JFrame {

    public static Calendar calendar = new Calendar();

    /**
     * Creates new form revisionPlannerUI
     *
     * @throws java.text.ParseException
     */
    public revisionPlannerUI() throws ParseException {
        initComponents();
        calendar.setTheme(ThemeType.Light);
        calendar.setCurrentView(CalendarView.Timetable);
        //calendar.getTimetableSettings().getVisibleColumns();
        Container cp = jPanel2;
        cp.setLayout(new BorderLayout());
        cp.add(calendar, BorderLayout.CENTER);
        for (int i = 0; i < 7; i++) {
            calendar.getTimetableSettings().getDates().add(DateTime.today().addDays(i - 1));
        }
        calendar.getTimetableSettings().setStartTime(8 * 60);
        calendar.getTimetableSettings().setItemOffset(30);
        calendar.getTimetableSettings().setShowItemSpans(false);
        calendar.getTimetableSettings().setSnapInterval(Duration.fromMinutes(1));
        calendar.getTimetableSettings().setVisibleColumns(7);
        getTasks();

    }
    public static ArrayList<Item> items = new ArrayList<Item>();

    private void getTasks() throws ParseException {
        try {
            String SQL = "SELECT TASKNAME, TASKDATE, STARTTIME, LENGTH, SUBJECTID FROM TIMETABLE WHERE USERID = '" + globals.dbUserID + "'";
            Connection con = DriverManager.getConnection(globals.host);
            Statement statement = con.createStatement();
            ResultSet resSet = statement.executeQuery(SQL);
            while (resSet.next()) {
                Date date = resSet.getDate("TASKDATE");
                Time time = resSet.getTime("STARTTIME");
                int length = resSet.getInt("LENGTH");
                DateTime dt = new DateTime(date.getYear(), date.getMonth(), date.getDay(), time.getHours(), time.getMinutes(), 0);
                DateTime dt2 = new DateTime(date.getYear(), date.getMonth(), date.getDay(), time.getHours(), time.getMinutes() + length, 0);
                System.out.println(date);
                String taskname = resSet.getString("TASKNAME");
                Appointment app = new Appointment();
                app.setStartTime(dt);
                app.setEndTime(dt2);
                app.setHeaderText(taskname);
                calendar.getSchedule().getItems().add(app);
            }
        } catch (SQLException err) {
            System.out.println(err);
        }
    } 



If you could, could you also show me a sample for how to change between weeks when the user click son a button?
  
Back to top
 
IP Logged
 
Iva_P
YaBB Moderator
*****
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: Jplanner Scheduler java timetable
Reply #6 - Apr 3rd, 2019 at 3:07pm
Print Post  
Could you print in the console the days that you have added to the timetable, the start and end date time of the appointments to make sure that they match. Also, are there any errors printed in the console?

For the scrolling you can use the setScrollStep method https://www.mindfusion.eu/onlinehelp/jplanner/index.htm?M_com_mindfusion_schedul... of the timetableSettings object to specify the desired step. Also check setShowNavigationButtons if you have none.
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #7 - Apr 3rd, 2019 at 3:13pm
Print Post  
This is what the console printed for the 3 tasks:
It is int the format of:
Date
StartDateTime
EndDateTime
2019-04-04
05/03/19 00:00:00 o'clock GMT
05/03/19 00:16:00 o'clock GMT
2019-04-03
04/03/19 10:17:00 o'clock GMT
04/03/19 10:31:00 o'clock GMT
2019-04-04
05/03/19 10:10:00 o'clock GMT
05/03/19 10:31:00 o'clock GMT

No errors are given at all :c.

I'll take a look at the scrollStep method in a bit.

Thanks,
Robert
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #8 - Apr 3rd, 2019 at 4:14pm
Print Post  
SetShowNavigatioButtons works just fine so thanks for that. Just the main bit now!

Thanks,
Robert
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #9 - Apr 4th, 2019 at 2:13am
Print Post  
My DateTimes were off by a bit but even after amending them, there is still no cell being coloured for that time period. If you can get back to me with a solution by 1pm tomorrow GMT then it is possible for me to fix my code.

Thanks,
Robert
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Jplanner Scheduler java timetable
Reply #10 - Apr 4th, 2019 at 8:41am
Print Post  
Aren't these printed times in March? they would not show in current week... Add some println's for the dates you add to the view (getTimetableSettings().getDates().add...) - what do they show?
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #11 - Apr 4th, 2019 at 8:48am
Print Post  
as I said in the above I fixed this:
Code (Java)
Select All
DateTime dt = new DateTime(date.getYear(), date.getMonth()+1, date.getDay()-1, time.getHours(), time.getMinutes(), 0);
                DateTime dt2 = new DateTime(date.getYear(), date.getMonth()+1, date.getDay()-1, time.getHours(), time.getMinutes() + length, 0); 



doing this returns
2019-04-04
04/04/19 00:00:00 o'clock GMT
04/04/19 00:16:00 o'clock GMT
2019-04-03
03/04/19 10:17:00 o'clock GMT
03/04/19 10:31:00 o'clock GMT
2019-04-04
04/04/19 10:10:00 o'clock GMT
04/04/19 10:31:00 o'clock GMT
  
Back to top
 
IP Logged
 
robert_v
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Apr 2nd, 2019
Re: Jplanner Scheduler java timetable
Reply #12 - Apr 4th, 2019 at 8:56am
Print Post  
wait this time it worked?
Adding this
Code (Java)
Select All
System.out.println(calendar.getTimetableSettings().getDates().add(dt));
                System.out.println(calendar.getTimetableSettings().getDates().add(dt2)); 

added some tasksbut dupelicated them many times. Thats odd, is that supposed to happen?

I've attached a picture of what it looks like.

You may still be able to save me Cheesy
  

timetable.PNG ( 19 KB | 218 Downloads )
timetable.PNG
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Jplanner Scheduler java timetable
Reply #13 - Apr 4th, 2019 at 9:11am
Print Post  
This is what I'm seeing if I add your last three printed times to the first tutorial (Tutorial 1 sample project) using your timetable settings -



Code
Select All
calendar.beginInit();
calendar.setCurrentView(CalendarView.Timetable);
calendar.getTimetableSettings().setShowDayHeader(true);
calendar.getTimetableSettings().setVisibleColumns(3);
calendar.getTimetableSettings().getDates().clear();
for (int i = 0; i < 5; i++)
	calendar.getTimetableSettings().getDates().add(DateTime.today().addDays(i));
calendar.getTimetableSettings().setStartTime(8 * 60);
	calendar.getTimetableSettings().setItemOffset(30);
	calendar.getTimetableSettings().setShowItemSpans(false);
	calendar.getTimetableSettings().setSnapInterval(Duration.fromMinutes(1));
calendar.endInit();

DateTime dt = new DateTime(2019, 4, 4, 10, 10, 0);
DateTime dt2 = new DateTime(2019, 4, 4, 10, 31, 0);
Appointment app = new Appointment();
app.setStartTime(dt);
app.setEndTime(dt2);
app.setHeaderText("taskname");
calendar.getSchedule().getItems().add(app);

dt = new DateTime(2019, 4, 3, 10, 17, 0);
dt2 = new DateTime(2019, 4, 3, 10, 31, 0);
app = new Appointment();
app.setStartTime(dt);
app.setEndTime(dt2);
app.setHeaderText("taskname");
calendar.getSchedule().getItems().add(app);

dt = new DateTime(2019, 4, 4, 00, 0, 0);
dt2 = new DateTime(2019, 4, 4, 00, 16, 0);
app = new Appointment();
app.setStartTime(dt);
app.setEndTime(dt2);
app.setHeaderText("taskname");
calendar.getSchedule().getItems().add(app);
 



The second item is not visible because it's from yesterday. The third one is not visible because it's before the timetable's StartTime. If you aren't seeing even one item, make sure you aren't clearing the schedule later (assigning a new Schedule instance to the calendar or calling clear()).

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3148
Joined: Oct 19th, 2005
Re: Jplanner Scheduler java timetable
Reply #14 - Apr 4th, 2019 at 9:19am
Print Post  
Quote:
System.out.println(calendar.getTimetableSettings().getDates().add(dt)); System.out.println(calendar.getTimetableSettings().getDates().add(dt2))


This line not only prints but also adds a column to the view (getDates().add) so it triples the columns. When I said to print them I meant not literally copying the add code inside print, but only the values to verify. In case you missed it, also check above post showing why some items are not visible (one being before the hour you pass to setStartTime, the other one being from yesterday).
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint