package com.myMinistry.models;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import com.myMinistry.dao.DAO;
import android.app.Application;
import android.content.ContentValues;
import android.database.Cursor;
public class Rollover extends Application {
private int _id = 0;
private int _publisherID= 1;
private int _year = 0;
private int _month = 0;
private int _day = 1;
private double _minutes = 0;
public Rollover(){}
public Rollover(Cursor record){
this._id = record.getInt(record.getColumnIndex(DAO.KEY_ROLLOVER_ROWID));
this._publisherID = record.getInt(record.getColumnIndex(DAO.KEY_ROLLOVER_PUBLISHER_ID));
this._minutes = record.getDouble(record.getColumnIndex(DAO.KEY_ROLLOVER_MINUTES));
setDate(record.getString(record.getColumnIndex(DAO.KEY_ROLLOVER_DATE)));
}
public int getID() {return this._id;}
public void setID(int id) {this._id = id;}
public int getPublisherID() {return this._publisherID;}
public void setPublisherID(int id) {this._publisherID = id;}
public int getYear() {return this._year;}
public void setYear(int id) {this._year = id;}
public int getMonth() {return this._month;}
public void setMonth(int id) {this._month = id;}
public double getMinutes() {return this._minutes;}
public void setMinutes(double num) {this._minutes = num;}
public void setDate(String date) {
String[] split = date.split("-");
this._year = Integer.valueOf(split[0]);
this._month = Integer.valueOf(split[1]) - 1; // Needs to be subtracted because months are zero based
}
public ContentValues getContentValues(){
SimpleDateFormat sqlDateFormat = new SimpleDateFormat("yyyy-MM-dd");
ContentValues values = new ContentValues();
Calendar local = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
local.set(this._year,this._month,this._day);
values.put(DAO.KEY_ROLLOVER_PUBLISHER_ID, this._publisherID);
values.put(DAO.KEY_ROLLOVER_MINUTES, this._minutes);
values.put(DAO.KEY_ROLLOVER_DATE, sqlDateFormat.format(local.getTime()));
return values;
}
// Create/Update the Object
public int save() {
int retVal = 0;
DAO dao = new DAO(this);
if(this._id != 0)
retVal = dao.update(DAO.ROLLOVER_TABLE, this._id, getContentValues());
else {
this._id = (int) dao.create(DAO.ROLLOVER_TABLE, getContentValues());
retVal = 1;
}
return retVal;
}
}
|