Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.jbundle.main.calendar.db.CalendarControl Maven / Gradle / Ivy
package org.jbundle.main.calendar.db;
import java.util.*;
import org.jbundle.base.db.*;
import org.jbundle.thin.base.util.*;
import org.jbundle.thin.base.db.*;
import org.jbundle.base.db.event.*;
import org.jbundle.base.db.filter.*;
import org.jbundle.base.field.*;
import org.jbundle.base.field.convert.*;
import org.jbundle.base.field.event.*;
import org.jbundle.base.model.*;
import org.jbundle.base.util.*;
import org.jbundle.model.*;
import org.jbundle.model.db.*;
import org.jbundle.model.screen.*;
import org.jbundle.model.main.calendar.db.*;
public class CalendarControl extends ControlRecord
implements CalendarControlModel
{
private static final long serialVersionUID = 1L ;
public CalendarControl ()
{
super ();
}
public CalendarControl (RecordOwner screen)
{
this ();
this .init(screen);
}
public void init (RecordOwner screen)
{
super .init(screen);
}
public String getTableNames (boolean bAddQuotes)
{
return (m_tableName == null ) ? Record.formatTableNames(CALENDAR_CONTROL_FILE, bAddQuotes) : super .getTableNames(bAddQuotes);
}
public String getDatabaseName ()
{
return "main" ;
}
public int getDatabaseType ()
{
return DBConstants.LOCAL | DBConstants.USER_DATA;
}
public BaseField setupField (int iFieldSeq)
{
BaseField field = null ;
if (iFieldSeq == 3 )
{
field = new DateTimeField(this , LAST_UPDATE_DATE, Constants.DEFAULT_FIELD_LENGTH, null , null );
field.setHidden(true );
}
if (iFieldSeq == 4 )
{
field = new DateTimeField(this , START_ANNIV_DATE, Constants.DEFAULT_FIELD_LENGTH, null , null );
field.setHidden(true );
}
if (iFieldSeq == 5 )
{
field = new DateTimeField(this , END_ANNIV_DATE, Constants.DEFAULT_FIELD_LENGTH, null , null );
field.setHidden(true );
}
if (iFieldSeq == 6 )
field = new IntegerField(this , UPDATE_DAYS, Constants.DEFAULT_FIELD_LENGTH, null , new Integer(1 ));
if (iFieldSeq == 7 )
field = new IntegerField(this , ANNIV_BACK_DAYS, Constants.DEFAULT_FIELD_LENGTH, null , new Integer(0 ));
if (iFieldSeq == 8 )
field = new IntegerField(this , ANNIVERSARY_DAYS, Constants.DEFAULT_FIELD_LENGTH, null , new Integer(60 ));
if (iFieldSeq == 9 )
field = new CalendarCategoryField(this , ANNIVERSARY_CATEGORY_ID, Constants.DEFAULT_FIELD_LENGTH, null , null );
if (iFieldSeq == 10 )
field = new CalendarCategoryField(this , APPOINTMENT_CATEGORY_ID, Constants.DEFAULT_FIELD_LENGTH, null , null );
if (field == null )
field = super .setupField(iFieldSeq);
return field;
}
public KeyArea setupKey (int iKeyArea)
{
KeyArea keyArea = null ;
if (iKeyArea == 0 )
{
keyArea = this .makeIndex(DBConstants.UNIQUE, ID_KEY);
keyArea.addKeyField(ID, DBConstants.ASCENDING);
}
if (keyArea == null )
keyArea = super .setupKey(iKeyArea);
return keyArea;
}
public void addMasterListeners ()
{
super .addMasterListeners();
this .updateDatesAndCalendar();
}
public void updateDatesAndCalendar ()
{
if ((this .getEditMode() == DBConstants.EDIT_NONE) || (this .getEditMode() == DBConstants.EDIT_ADD))
return ;
boolean bUpdateDates = false ;
int iUpdateDays = (int )this .getField(CalendarControl.UPDATE_DAYS).getValue();
Calendar calNow = new GregorianCalendar();
if ((this .getField(CalendarControl.START_ANNIV_DATE).isNull())
|| (this .getField(CalendarControl.END_ANNIV_DATE).isNull()))
bUpdateDates = true ;
else
{
Calendar calCutoff = ((DateTimeField)this .getField(CalendarControl.LAST_UPDATE_DATE)).getCalendar();
calCutoff.add(Calendar.DAY_OF_YEAR, iUpdateDays);
if (calNow.after(calCutoff))
bUpdateDates = true ;
}
if (bUpdateDates)
{
int iBackDays = (int )this .getField(CalendarControl.ANNIV_BACK_DAYS).getValue();
int iRangeDays = (int )this .getField(CalendarControl.ANNIVERSARY_DAYS).getValue();
Calendar calStart = (Calendar)calNow.clone();
calStart.add(Calendar.DAY_OF_YEAR, -iBackDays);
Calendar calEnd = (Calendar)calStart.clone();
calEnd.add(Calendar.DAY_OF_YEAR, iRangeDays - iBackDays);
Calendar calOldEnd = ((DateTimeField)this .getField(CalendarControl.END_ANNIV_DATE)).getCalendar();
if (calOldEnd == null )
calOldEnd = calNow;
((DateTimeField)this .getField(CalendarControl.START_ANNIV_DATE)).setCalendar(calStart, true , DBConstants.SCREEN_MOVE);
((DateTimeField)this .getField(CalendarControl.END_ANNIV_DATE)).setCalendar(calEnd, true , DBConstants.SCREEN_MOVE);
((DateTimeField)this .getField(CalendarControl.LAST_UPDATE_DATE)).setCalendar(calNow, true , DBConstants.SCREEN_MOVE);
this .updateCalendar(calOldEnd, calEnd);
try {
this .writeAndRefresh();
} catch (DBException ex) {
ex.printStackTrace();
}
}
}
public void updateCalendar (Calendar calStart, Calendar calEnd)
{
Anniversary recAnniversary = new Anniversary(this .getRecordOwner());
AnnivMaster recAnnivMaster = new AnnivMaster(this .getRecordOwner());
recAnniversary.setKeyArea(Anniversary.START_DATE_TIME_KEY);
try {
while (recAnniversary.hasNext())
{
recAnniversary.next();
if (recAnniversary.getField(Anniversary.START_DATE_TIME).compareTo(this .getField(CalendarControl.START_ANNIV_DATE)) > 0 )
break ;
recAnniversary.edit();
recAnniversary.remove();
}
while (recAnnivMaster.hasNext())
{
recAnnivMaster.next();
recAnnivMaster.addAppointments(recAnniversary, calStart, calEnd);
}
} catch (DBException ex) {
ex.printStackTrace();
} finally {
recAnniversary.free();
recAnnivMaster.free();
}
}
}