Simworktime.java 5.92 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
package com.csc.library.databean;

import com.csc.library.utilities.MyLog;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Enumeration;

import com.csc.library.approve.Organization;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.session.InitialRecord;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.database.ChildManager;

/*
 * NOT USED 2008/09/17
 */
public class Simworktime extends Worktime {

	public Simworktime() {
		super();
		this.setActualName("Simworktime");
	} 

	public String getString(String field) {
		String chFilter1 = "";
		if (field.indexOf("subemp") != -1) {
			Vector subOrdi = new Vector();

			try {
				String empid = (String) this.getUProfile().get("actor");
				MyLog.debug(this, "actor in simworktime+++++++++++++++++"	+ (String) this.getUProfile().get("actor"));
				Organization org = (Organization) new InitialRecord(this.userPro, this.param).getDbRecord("Masfactor");
				org.setDaTaResult("Torgani","bossid,employeeid,companyid,runno");
				org.setSub("1", "employeeid", "bossid", empid);
				subOrdi = org.getSub();
			} catch (Exception ex) {
				MyLog.error(this, ex);

				
			}
			int i = 0;
			for (Enumeration e = subOrdi.elements(); e.hasMoreElements();) {
				try {
					DbRecord subBean = (DbRecord) e.nextElement();
					if (i <= 0) {
						chFilter1 = chFilter1 + " ( employeeid='" + subBean.getString("employeeid") + "')";
					} else {
						chFilter1 = chFilter1 + " or ( employeeid='" + subBean.getString("employeeid") + "')";
					}
					i++;
				} catch (Exception ex1) {
					MyLog.error(this, ex1);

					
				}
			} //end for
			
		} else if (field.indexOf("listFilter") != -1) {
			String chFilter = "";
			CscCalendar cDate = new CscCalendar();
			String dateCon = "";
			String field1 = "";
			String field2 = "";
			try {
				System.out
						.println("------------- SIMWORKTIME   ----- listFilter = "	+ field);
				for (StringTokenizer token = new StringTokenizer(field, "$"); token.hasMoreTokens();) {
					field1 = token.nextToken();
					field2 = token.nextToken();
				}
			} catch (Exception ex) {
				MyLog.error(this, ex);

				
			}
			if (field2.equals("")) {
				dateCon = cDate.getMM() + "/" + cDate.getDD() + "/" + (Integer.parseInt(cDate.getEngYYYY()) - 543);
			} else {

				String date[] = { "a", "b", "c" };
				int i = 0;
				for (StringTokenizer token = new StringTokenizer(field2, "/"); token	.hasMoreTokens();) {
					date[i] = token.nextToken();
					i++;
				}
				dateCon = date[1] + "/" + date[0] + "/" + date[2];
			}
			Vector subOrdi = new Vector();
			try {
				String empid = (String) this.getUProfile().get("actor");
				Organization org = (Organization) new InitialRecord(this.userPro, this.param).getDbRecord("Masfactor");
				org.setDaTaResult("Torgani","bossid,employeeid,companyid,runno");
				org.setSub("1", "employeeid", "bossid", empid);
				subOrdi = org.getSub();
			} catch (Exception ex) {
				MyLog.error(this, ex);

				
			}
			int i = 0;
			for (Enumeration e = subOrdi.elements(); e.hasMoreElements();) {
				try {
					DbRecord subBean = (DbRecord) e.nextElement();
					if (i <= 0) {
						chFilter = chFilter + " (( employeeid='" + subBean.getString("employeeid")
								+ "') and ( BDATEID ='" + dateCon + "'))";
					} else {
						chFilter = chFilter + " or (( employeeid='"	+ subBean.getString("employeeid")
								+ "') and ( BDATEID ='" + dateCon + "'))";
					}
					i++;
				} catch (Exception ex1) {
					MyLog.error(this, ex1);

					
				}
			}
			chFilter1 = chFilter;
		} else if (field.indexOf("childFilter") != -1) {
			String chFilter = "";
			String field1 = "";
			String field2 = "";
			String field3 = "";
			String dateChild = "";
			CscCalendar cDate = new CscCalendar();
			try {
				for (StringTokenizer token = new StringTokenizer(field, "$"); token
						.hasMoreTokens();) {
					field1 = token.nextToken();
					field2 = token.nextToken();
					field3 = token.nextToken();
				}
			} catch (Exception e) {
				MyLog.error(this, e);

				
			}
			if (field2.equals("")) {
				dateChild = cDate.getDOWeng();
				chFilter = " dayweekid='" + dateChild + "'";
			} else {
				String bdate = "";
				int i = 0;
				for (StringTokenizer token = new StringTokenizer(field2, "/"); token	.hasMoreTokens();) {
					if (i <= 0) {
						bdate = bdate + token.nextToken();
					} else if (i == 2) {
						bdate = token.nextToken() + "-" + bdate;
					} else {
						bdate = bdate + "-" + token.nextToken();
					}
					i++;
				}
				CscCalendar cDate1 = new CscCalendar(bdate);
				dateChild = cDate1.getDOWeng();
			} // fine if found childfilter
			if (field3.equals("")) {
				chFilter = " dayweekid='" + dateChild + "'";
			} else {
				chFilter = " dayweekid='" + dateChild + "' and time0id=" + field3;
			}
			System.out.print("------------------------date check" + dateChild);
			chFilter1 = chFilter;
		} else {
			chFilter1 = super.getString(field);
		}
		return chFilter1;
	} // end func

	public int putChild(ChildManager oChild) {
		int point = super.putChild(oChild);
		System.out.print(".................31556");
		try {
			System.out.print(".................31557");
			if ((oChild instanceof DbInquiry)
					&& (oChild.getTableName().equalsIgnoreCase("MTIME1"))) {
				DbInquiry dbInquiry = (DbInquiry) oChild;
				int i = 0;
				String date1 = "";
				for (StringTokenizer token = new StringTokenizer(this.getString("bdateid"), "/"); token.hasMoreTokens();) {
					if (i == 0) {
						date1 = token.nextToken();
					} else {
						date1 = token.nextToken() + "-" + date1;
					}
					i++;
				}
				CscCalendar cDate1 = new CscCalendar(date1);
				dbInquiry.setFilter(" dayweekid ='" + cDate1.getDOWeng() + "'");
			}
		} catch (Exception ex) {
			MyLog.error(this, ex);

			
		}
		return point;
	}
	
}