Mempl_cardtemp.java 2.8 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
/*
 * Created on 20 .. 2548
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.csc.library.databean;

import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.MyLog;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialInquiry;
import com.csc.library.session.InitialRecord;
import com.csc.library.session.RecordCmp;

/**
 * @author vassana
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 * class Ѻ红šѵêǤǢͧѡҹ
 */
public class Mempl_cardtemp extends RecordCmp implements DbRecord{

	public Mempl_cardtemp() {
		super("Mempl_cardtemp", "Mempl_cardtemp Table");
	}
	
	protected void postInsertTrigger() throws Exception {
		super.postInsertTrigger();
		this.saveData();
	}
	
	protected void postUpdateTrigger() throws Exception {
		super.postUpdateTrigger();
		this.deleteData();
		this.saveData();
	}
	
	protected void postDeleteTrigger() throws Exception {
		super.postDeleteTrigger();
		this.deleteData();
	}
	
	/*
	 * ӡúѹ֡šѵêǤǢͧѡҹ ŧ价ѹ
	 * ͨй㹡äӹdz͹ ͹(Transfer) 
	 */
	private void saveData() {
		DbRecord rec = new InitialRecord(this.userPro).getDbRecord("Mempl_cardtemp1");
		try {
			CscCalendar c1 = new CscCalendar(this.getString("startdate"));
			CscCalendar c2 = new CscCalendar(this.getString("enddate"));
			rec.clearField();
			while (c1.beforeEqualsDate(c2)) {
				rec.set("employeeid", this.getString("employeeid"));
				rec.set("companyid", (String) this.userPro.get("companyid"));
				rec.set("swipecardid", this.getString("swipecardid"));
				rec.set("dateid", c1.getYYYYMMDD());
				rec.save();
				c1.incDate();
			}		
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}
	
	/*
	 * źšѵêǤǢͧѡҹ
	 */
	private void deleteData() {
		try {
			CscCalendar c1 = new CscCalendar(this.pRemote.getString("startdate"));
			CscCalendar c2 = new CscCalendar(this.pRemote.getString("enddate"));
			DbInquiry inq = new InitialInquiry(this.userPro).getDbInquiry();
			inq.initMyTable("Mempl_cardtemp1", "", "");
			inq.setColumn("*");
			inq.setFilter("swipecardid='"+this.pRemote.getString("swipedateid")+"' " +
					"and employeeid='"+this.pRemote.getString("employeeid")+"' " +
					"and (dateid between '"+c1.getYYYYMMDD()+"' and '"+c2.getYYYYMMDD()+"')");
			inq.refresh();
			while (inq.next()) {
				DbRecord rec = inq.getCurrentDbRecord().cloneRecord(true);
				rec.delete();
			} while (inq.next());
		} catch (Exception e) {
			MyLog.error(this, e);
		}
	}
}