RecordCmp0.java 52.7 KB
Newer Older
Naung1 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924
package com.csc.library.session;

import java.io.File;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;

import com.csc.entity.DataBMPBean;
import com.csc.entity.DataBMPKey;
import com.csc.library.database.ChildManager;
import com.csc.library.database.DataSet;
import com.csc.library.database.DeleteRecord;
import com.csc.library.database.FieldManager;
import com.csc.library.database.MyHashMap;
import com.csc.library.database.MyRecord;
import com.csc.library.database.PropertyRec;
import com.csc.library.database.Relation;
import com.csc.library.database.StaticProperties;
import com.csc.library.database.SystemCode;
import com.csc.library.service.GenProcessQuque;
import com.csc.library.utilities.Base64Decoder;
import com.csc.library.utilities.Base64Encoder;
import com.csc.library.utilities.CscCalendar;
import com.csc.library.utilities.MyLog;
import com.csc.library.utilities.RelationProperties;
import com.csc.library.utilities.UProfile;
import com.csc.library.download.FileDownloadUtils2; //require project CscFileUtils

public class RecordCmp0 extends MyRecord implements DbRecord, Cloneable {
	/**
	 * 
	 * Save Status
	 * ---------------------------------------------------------------------- 
	 *			 1 = insert 
	 * 			-1 = can't insert 
	 * 			 2 = save 
	 * 			-2 = can't update 
	 * 			 3 = normal 
	 * 			 4 = delete
	 * 			-4 = can't delete 
	 * 			 5 = search found data 
	 * 			-5 = search not found data 
	 * 			-99 =duplicate data 
	 * 			-88,-3[multientry] = key is null 
	 * 			-31 = (FK Integrity)Can't delete!! 
	 * 			-21 = can't change password, because old password invalid
	 * ----------------------------------------------------------------------
	 */
	// private String fieldList1;
	protected boolean isDup = false;

	protected Object[] obk;

//	protected HashMap oldData = new HashMap();

	private CscCalendar now = new CscCalendar();

	private boolean confirm = false;

	private String messageError = "";

	private String messageWarning = "";

	private boolean encrypt = true;

	private boolean referOn = false;

	private String fieldName, oValue, newValue, keyGroup;

	private HashMap vUpdateData = new HashMap();

	protected int saveStatus = 3;

	private String fieldNotSave = "";

	private String keyLink = "";

	protected boolean wfOn = true;

	private boolean saveState = false;

	private DbRecord dbEventLog = null;
	
	private boolean transfer= true;
	
	private boolean wfTransfer= false;

	private String wfRefDoc= "";
	
	private boolean alterWfTransfer=false;

	// private HashMap referTable = new HashMap();
	public RecordCmp0() {
		super("", "");
	}

	private String[][] sysCode = { { "", "" } };

	/**
	 * 
	 * @param a =
	 *                  Name of table in DBMS
	 * @param b =
	 *                  Description of DBMS
	 */
	public RecordCmp0(String a, String b) {
		super(a, b);
	}

	/**
	 * 
	 * @param field =
	 *                  Name of field in DBMS
	 * @param data =
	 *                  Value of field in DBMS
	 */
	public boolean set(String field, String data) {
		return super.set(field, data);
	}

	public boolean set(String tableName, String field, String data) {
		try {
			if (tableName.equalsIgnoreCase(this.getTableName())) {
				return this.set(field, data);
			} else {
				DbRecord rec = (DbRecord) this.getChild(tableName);
				return rec.set(field, data);
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			return false;
		}
	}

	public void setDatabaseName(String databaseName) {
		this.databaseName = databaseName;
	}

	public void setUserId(String uid) {
		this.uid = uid;
	}

	protected void addKey(boolean search) {

		try {
			this.pK.setKey(this);
		} catch (Exception ex) {
			MyLog.error(this, this.getUProfile(), ex);
		}
	}

	public int search(String key) {
		DbInquiry di = new InitialInquiry(this.userPro).getDbInquiry();
		FieldManager fm = this.getField(key);
		Vector v1 = this.getAllKey();
		String keyList = "";
		boolean first = true;
		for (int i = 0; i < v1.size(); i++) {
			if (!first) {
				keyList += "," + (String) v1.elementAt(i);
			} else
				keyList += (String) v1.elementAt(i);
			first = false;
		}
		try {
			di.initMyTable(this.getTableName(), "", "");
			String fType = fm.getType();
			if (fType.equalsIgnoreCase("Integer")
					|| fType.equalsIgnoreCase("Double")
					|| fType.equalsIgnoreCase("BigDecimal"))
				di.setFilter(key + "=" + fm.getValue() + "");
			else
				di.setFilter(key + "='" + fm.getValue() + "'");
			di.setColumn(keyList);
			di.refresh();
			di.next();
			Vector v = di.getCurrentDbRecord().getAllKey();
			for (int i = 0; i < v.size(); i++) {
				this.set((String) v.elementAt(i), di.getString((String) v.elementAt(i)));
			}
			di.closeConnection();
			return this.search();
		} catch (RemoteException e) {
			try {
				MyLog.error(this, this.getUProfile(), e);
				di.closeConnection();
			} catch (Exception ex) {
				MyLog.error(this, this.getUProfile(), ex);
			}
			return 0;
		}
	}

	public int search() {
		this.setCompany();
		String data = "";
		try {
			this.referLangOff();
			this.pRemote.setDbRecord(this);
			this.foundData = pRemote.findByPrimaryKey();
			this.isDup = foundData;
			if (foundData) {
				this.saveStatus = 5;
				this.refreshChild();
				if (this.referLang) {
					this.referLangOn();
				} else {
					this.referLangOff();
				}
			} else {
				this.clearChild();
				this.clearDataExceptKeyField();
				this.saveStatus = -5;
				return 0;
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), StaticProperties.messagePools
					.getMessage("MSG0009", this.getUProfile().get("lang")));
			this.saveStatus = -5;
			return 0;
		}
		return 1;
	}

	
	/**
	 * 
	 * @param field =
	 *                  Name of field in table
	 * @return data in field
	 */
	public String getString(String field) {
		String data = "";
		try {
			data = super.getString(field);
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), StaticProperties.messagePools
					.getMessage("MSG0005", this.getUProfile().get("lang"))
					+ this.getActualName() + "." + field);
		}
		return data.trim();
	}

	public String getRunNo() {
		if(this.isDup)
			return this.getOriginalValue("runno");
		else
			return this.getString("runno");
	}

	private String getKeyFilter() {
		String filter = ""; 
		Vector v = this.getAllKey();
		FieldManager fm;
		String fieldName, value, fType, temp;
		boolean first = true;
		for (int i = 0; i < v.size(); i++) {
			temp = "";
			fieldName = (String) v.elementAt(i);
			fm = this.getField(fieldName);
			value = fm.getValue();
			fType = fm.getType();
			if (fType.equalsIgnoreCase("Integer")
					|| fType.equalsIgnoreCase("Double")
					|| fType.equalsIgnoreCase("BigDecimal")) {
				temp = fieldName + "=" + value;
			} else if (fType.equalsIgnoreCase("Date")) {
				CscCalendar cs = new CscCalendar(value);
				temp = fieldName + "='" + cs.getYYYYMMDD() + "'";
			} else
				temp = fieldName + "='" + value + "'";
			if (!first) {
				temp = " AND " + temp;
			}
			filter += temp;
			first = false;
		}
		return filter;
	}

	/**
	 * <p>
	 * Save data to EntityBean from jsp entry.
	 * </p>
	 */
//	public synchronized int insert() {
	public int insert() {
		int returnValue = 0;
		// savestatus not clear in memory
		this.saveStatus = 2;
		if (this.checkReferenceKey()) {
			try {
				if (this.keyOK()) {
					StaticProperties.myConnection.beginTransaction(
							this.userPro, this);
					int save = 0;
					this.setAutonumField();
					this.setDataToHisField();
//					this.searchForSave();
					this.isDuplicate();
					if (!this.isDup) {
						this.saveStatus = this.createData();
						StaticProperties.myConnection.endTransaction(
								this.userPro, this);
					} else {
						this.saveStatus = -99;
					}
				} else {
					StaticProperties.myConnection.rollback(this.userPro, this);
					this.saveStatus = -88;
					MyLog.error(this, this.getUProfile(),
							StaticProperties.messagePools.getMessage("MSG0001",
									this.getUProfile().get("lang"))
									+ this.getKeyEmptyList());
				}
			} catch (Exception e) {
				try {
					MyLog.error(this, this.getUProfile(), e);
					StaticProperties.myConnection.rollback(this.userPro, this);
				} catch (SQLException e1) {
					MyLog.error(this, this.getUProfile(), e1);
				}
			}
		} else {
			this.saveStatus = -1;
			try {
				StaticProperties.myConnection.rollback(this.userPro, this);
			} catch (SQLException e1) {
				MyLog.error(this, this.getUProfile(), e1);
			}
		}
		return this.saveStatus;
	}

	private void saveChild() throws Exception {
		DbTable dt;
		DbRecord db;
		Object obj;
		Relation relation;
		int save =0;
		for (Enumeration enums = this.childTable.keys(); enums.hasMoreElements();) {
			obj = this.childTable.get((String) enums.nextElement());
			if (obj instanceof DbTable) {
				dt = (DbTable) obj;
				relation = this.getRelation(dt.getActualName());
				dt.setParentDb(this);
				dt.setRelationLink(relation.parentField, relation.childField);
				dt.setKeyGroup(this.getKeyRefer());
				dt.setParam(this.param);
				this.refreshConditionChild(dt.getTableName());
				save = dt.save();
			} else if (obj instanceof DbRecord) {
				db = (DbRecord) obj;
				this.refreshConditionChild(db.getTableName());
				if(db.isSave())
					save = db.save();
			} 
			if (save < 0) {
				this.saveStatus = save;
				return;
			} 
		}
	}

	/**
	 * <p>
	 * Set key confirm for update old record.
	 * <p>
	 * 
	 * @param confirm
	 */
	public void setConfirm(boolean confirm) {
		this.confirm = confirm;
	}

	/**
	 * @return confirm
	 */
	public boolean getConfirm() {
		return this.confirm;
	}

	/**
	 * 
	 * @return value if save ok return 1
	 */
	public int save(String keyGroup) {
		this.keyGroup = keyGroup;
		return this.save();
	}

	private void setAutonumField() {
		FieldManager fm = null;
		String fieldName = "";		
			for (int num = 0; num < AutoNumField.size(); num++) {
				fieldName = (String) AutoNumField.get(num);
				if(!fieldName.equalsIgnoreCase("RUNNO")){				
					fm = this.getField(fieldName);
					if (fm.getString().equalsIgnoreCase("0")) {				
							fm.set(fm.insAutoNumber());
				}
			}
		}
	}

//	public synchronized int save() {
	public int save() {
		MyLog.info(this, this.getUProfile(),"**********************SAVE IN RecordCMP*********************");
		this.saveState = true;
		this.saveStatus = 3;
		// this.setFieldConfigForSaveORUpdate();
		this.pRemote.setDbRecord(this);
		try {
			if (this.pRemote.checkDataBeforeSave()) {
				if (this.checkReferenceKey()) {
					try {
						this.setDataToHisField();
						if (this.keyOK()) {
							StaticProperties.myConnection.beginTransaction(this.userPro, this);
							this.referLangOff();
							this.setAutonumField();
							this.isDuplicate();
							this.saveStatus = this.createData();
							StaticProperties.myConnection.endTransaction(this.userPro, this);
							if (this.referLang) {
								this.referLangOn();
							} else {
								this.referLangOff();
							}
						} else {
							StaticProperties.myConnection.rollback(this.userPro, this);
							this.saveStatus = -88;
							MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getAllMessage("MSG0001", this.getUProfile().get("lang"))+ this.getKeyEmptyList());
						}
					} catch (Exception e) {
						this.saveState = false;
						try {
							MyLog.error(this, this.getUProfile(), e);
							StaticProperties.myConnection.rollback(this.userPro, this);
						} catch (SQLException e1) {
							MyLog.error(this, this.getUProfile(), e1);
						}
					}
				} else {
					this.saveStatus = -1;
					try {
						StaticProperties.myConnection.rollback(this.userPro,this);
					} catch (SQLException e1) {
						MyLog.error(this, this.getUProfile(), e1);
					}
				}
			} else {
				MyLog.error(this, this.getUProfile(), "�բ����ū�ӫ�͹! "+ this.getConditionAND());
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
		}
		this.saveState = false;
		return this.saveStatus;
	}

	public String getKeyGroup() {
		String result = "";
		if (this.keyGroup != null && !this.keyGroup.equalsIgnoreCase(""))
			result = this.keyGroup;
		else
			result = this.getKeyRefer();
		return result;
	}

	protected String getCurentTime() {
		return new CscCalendar().getTimestamp().toString();
	}

	protected String getUser() {
		return this.userPro.getUserId();
	}

	protected String getCompanyId() {
		return this.userPro.get("companyid");
	}

	protected String getScreenName() {
		return (String) this.param.get("__screen");
	}

	protected String getFieldName() {
		return this.fieldName;
	}

	protected String getOldValue() {
		return this.oValue;
	}

	public String getOriginalValue(String fieldName) {
		try {
			return this.pRemote.getString(fieldName);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}

	
	protected String getNewValue() {
		return this.newValue;
	}

	public String getTableName() {
		return this.tableName;
	}

	protected String getKeyRefer() {
		String result = "";
		result = "runno=" + this.getRunNo();
		return result;
	}

	private int createData() throws Exception {
		this.pRemote.setDbRecord(this);		
		this.stampTimeChange();
		if (this.isDup == false) {
			MyLog.debug(this, this.getUProfile(),"New key process save record");
			if (this.preInsertTrigger()) {
				this.saveStatus = 1;
				this.setCreateBy();
				this.saveRecord();
				this.saveChild();
				this.postInsertTrigger();
			} else {
				StaticProperties.myConnection.rollback(this.userPro, this);
				this.saveStatus = -1;
			}
		} else {
			MyLog.debug(this, this.getUProfile(),
					"Key aready exist update record");
			if (this.preUpdateTrigger()) {
				this.saveStatus = 2;
				this.setEditBy();
				this.updateRecord();
				this.keepDataForUpdate();
				this.saveChild();
				this.postUpdateTrigger();
			} else {
				StaticProperties.myConnection.rollback(this.userPro, this);
				this.saveStatus = -2;
			}
		}
		return this.saveStatus;
	}

	public boolean checkReferenceKey() {
		boolean ok = true;
		String mess = "";
		Relation relation;
		try {
			if (this.getUProfile().containsKey("processID")) {
				return true;
			}
			for (Enumeration enumeration = this.childTable.keys(); enumeration
					.hasMoreElements();) {
				String chName = (String) enumeration.nextElement();
				ChildManager ch = (ChildManager) this.childTable.get(chName);
				if (!(ch instanceof DbTable)) {
					relation = this.getRelation(chName);
					if (relation.isNeedCheck(this)) {
						ch.setParent((DbRecord) this);
						this.refreshChild(chName);
						if (!ch.foundData()) {
							ok = false;
							mess += "-------------------------------------------------\n"
									+ ch.getActualName()
									+ ":"
									+ ch.getDescription()
									+ "\n"
									+ relation
											.GenFieldDescription((DbRecord) this);
						}
					}
				}
			}
		} catch (Exception e) {
			MyLog.error(this, e);
		}
		if (!ok) {
			// MyLog.error(this, "Could not save data because reference key not
			// perfect! \r\n"+mess);
			MyLog.error(this,this.getUProfile(),StaticProperties.messagePools.getAllMessage("MSG0002", this.getUProfile().get("lang"))+ mess);
		}

		return ok;
	}

	public void setTransferRecord(DbRecord dbrec){
		transfer=false;
		if (this.isReferOn()) {
			try {
					Vector referFieldList = (Vector) this.referField.get(dbrec.getTableName());
					if (referFieldList != null) {
						Iterator itField = referFieldList.iterator();
						while (itField.hasNext()) {
							String tmp = (String) itField.next();
							int i = tmp.indexOf("$");
							String pfname = tmp.substring(0, i);
							String cfname = tmp.substring(i + 1, tmp.length());
							this.set(pfname, dbrec.getString(cfname));
						}
					}
			} catch (Exception e) {
				transfer=true;
				MyLog.error(this,this.getUProfile(),e);
			}
		}
	}
	
	
	private void setDataToHisField() {
		if (this.isReferOn()&&transfer) {
			try {
				Iterator it = this.referField.keySet().iterator();
				DbRecord dr;
				while (it.hasNext()) {
					String key = (String) it.next();
					Vector referFieldList = (Vector) this.referField.get(key);
					if (referFieldList != null) {
						if (this.getChild(key) == null) {
							dr =new InitialRecord(this.userPro).getDbRecord(key);
							dr.setColumn(this.subField(referFieldList));
							dr.isSave(false); //ա save child 
							this.putChild(dr);
						} else {
								dr = (DbRecord) this.getChild(key);								
						}
						this.refreshChild(key);
						
						Iterator itField = referFieldList.iterator();
						while (itField.hasNext()) {
							String tmp = (String) itField.next();
							int i = tmp.indexOf("$");
							String pfname = tmp.substring(0, i);
							String cfname = tmp.substring(i + 1, tmp.length());
							this.set(pfname, dr.getString(cfname));
						}
					}
				}
			} catch (Exception e) {
				MyLog.error(this,this.getUProfile(),e);
			}
		}
	}

	private Vector subField(Vector vfieldList) {
		Vector data = new Vector();
		Iterator itField = vfieldList.iterator();
		while (itField.hasNext()) {
			String temp = (String) itField.next();
			data.addElement(temp
					.substring(temp.indexOf("$") + 1, temp.length()));
		}
		return data;
	}


	protected void saveRecord() throws Exception {
		try {
			MyLog.info(this, this.getUProfile(), "Save table : "+ this.getTableName() + " key :" + this.getAllKey());
			if (this.isSave && this.saveStatus>0) {
				this.initWFTransfer();
				if(this.pRemote.create()){
					this.processworkflow();
				}else{
					this.saveStatus = -1;
				}
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getAllMessage("MSG0003", this.getUProfile().get("lang"))+ e);
			// this.saveStatus=98;
			this.saveStatus = -1;
		}
	}

	protected void updateRecord() throws SQLException {
		try {
			if (this.isSave && this.saveStatus>0) {
				this.removeFile(true);
				this.initWFTransfer();
				MyLog.debug(this, this.getUProfile(),"#################### UPDATE RECORD IN RECORD CMP ############");
				if(pRemote.update(false)){
					this.processworkflow();
				}else{
					this.saveStatus = -2;
				}
			}
		} catch (Exception e) {
			StaticProperties.myConnection.rollback(this.userPro, this);
			MyLog.error(this, this.getUProfile(), e);
			this.saveStatus = -2;
		}
	}
	
	protected void keepDataForUpdate() {
		try {
			for (int i = 0; i < this.aField.size(); i++) {
				String field = this.aField.get(i).toString();
				FieldManager fn = this.getField(field);
				fn.setOriginal(fn.getSaveString());
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
		}
	}

	public boolean setColumn(Vector fieldList) {
		super.setColumn(fieldList);
		this.addKey(false);
//		this.pRemote.setDataBMPKey(this.pK);
		this.pRemote.setDbRecord(this);
		return true;
	}
	
	public int searchForSave() {
		return this.isDuplicate();
	}
	
	public int isDuplicate() {
		String data = "";
		this.setCompany();
		try {
//			this.pRemote.setDbRecord(this);
			this.isDup = pRemote.isDuplicate();
		} catch (Exception e) {
			this.isDup = false;
			return 0;
		}
		return 1;
	}

	/*
	 * ...................................................................................................................................................................................
	 * Update For Relation Level
	 * ...................................................................................................................................................................................
	 */
	private boolean deleteAllchild() {
		Hashtable re = this.getRelationInfo();
		Enumeration em = re.keys();
		Vector chNew = new Vector();
		try {
			while (em.hasMoreElements()) {
				Relation relation = (Relation) re.get(em.nextElement());
				String dLevel = relation.getDeleteLevel();
				String mdelete = relation.getModuleDelete();
				if (dLevel.equals("1")) {
					Vector cList = relation.getVFieldListParent();
					Vector pList = relation.getVFieldtListChild();
					MyLog.info(this, "Ch tableName " + relation.tableName);
					String filter = "";
					for (int i = 0; i < cList.size(); i++) {
						String chField = (String) cList.elementAt(i);
						String value = this.getString((String) pList
								.elementAt(i));
						if (filter.length() == 0)
							filter += chField + "='" + value + "'";
						else
							filter += " AND " + chField + "='" + value + "'";
					}
					UProfile uf = (UProfile) this.userPro.clone();
					if (!mdelete.trim().equals(""))
						uf.set("appname", mdelete);
					new DeleteRecord(uf, relation.tableName, filter).process();
				}
			}
			return true;
		} catch (Exception ex) {
			MyLog.error(this, this.getUProfile(), ex);
			return false;
		}
	}

	public boolean chkDependTable(String mode) {
		boolean out = true;
		String fieldList = "";
		if (this.isDepend) {
			if (mode.equals("delete")) {
				Hashtable re = this.getRelationInfo();
				Enumeration em = re.keys();
				while (em.hasMoreElements()) {
					Relation relation = (Relation) re.get(em.nextElement());
					String dpLevel = relation.getDependLevel();
					fieldList = "";
					if (dpLevel.equals("true")
							&& (!relation.getMode().equals("-1"))) {
						// query for check data
						String tableName = relation.getRTableName();
						Vector vecPField = relation.getVFieldtListChild();
						Vector vecCField = relation.getVFieldListParent();
						String filter = "";
						for (int i = 0; i < vecPField.size(); i++) {
							String pfield = (String) vecPField.get(i);
							String cfield = (String) vecCField.get(i);

							if (filter.length() > 0)
								filter += " and ";

							if (fieldList.length() > 0)
								fieldList += ",";
							fieldList += cfield;
							String ftype = "";
							try {
								ftype = this.getField(pfield).getType();
							} catch (Exception ex) {
								MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getMessage("MSG0005", this	.getUProfile().get("lang"))+ pfield);
							}
							if (ftype.equalsIgnoreCase("integer")
									|| ftype.equalsIgnoreCase("double")
									|| ftype.equalsIgnoreCase("float")
									|| ftype.equalsIgnoreCase("long"))
								filter += cfield + "=" + this.getString(pfield);
							else
								filter += cfield + "='"
										+ this.getString(pfield) + "'";
						}
						String sql = "select count(1) numrows from "
								+ tableName + " where " + filter;
						boolean found = false;
						try {
							found = this.selectDB(sql, tableName);
						} catch (Exception e) {
							found = true;
						}
						if (!found) {
							out = true;
						} else {
							MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getMessage(	"MSG0006", this.getUProfile().get("lang"))+ tableName);
							out = false;
							break;
						}
					}
				}
			}
		}
		return out;
	}

	public boolean chkDependTableAllRelation(String mode) {
		boolean out = true;
		String fieldList = "";
		if (this.isDepend) {
			if (mode.equals("delete")) {
				HashMap chRelation = StaticProperties.relationPools
						.getRelation(this.getActualName().toUpperCase());
				if (chRelation != null) {
					Iterator it = chRelation.keySet().iterator();
					RelationProperties relation;
					String childName = "";
					while (it.hasNext()) {
						childName = (String) it.next();
						if (!childName.equals("KEYLIST")) {
							relation = (RelationProperties) chRelation
									.get(childName);

							String dpLevel = relation.getDependLevel();
							fieldList = "";
							if (dpLevel.equals("true")
									&& (!relation.getMode().equals("-1"))) {
								// query for check data
								String tableName = relation.getRtablename();
								if(tableName.trim().length()==0)
									tableName=childName;
								// Vector vecPField =
								// relation.getVFieldtListChild();
								Vector vecCField = relation.getChildList();
								String filter = "";
								String arrField[];
								for (int i = 0; i < vecCField.size(); i++) {
									String cfield = (String) vecCField.get(i);
									arrField = cfield.split(",");

									if (filter.length() > 0)
										filter += " and ";

									if (fieldList.length() > 0)
										fieldList += ",";
									fieldList += arrField[1];
									String ftype = "";
									try {
										ftype = this.getField(arrField[0])
												.getType();
									} catch (Exception ex) {
										MyLog.error(this,this.getUProfile(),StaticProperties.messagePools.getMessage("MSG0005",this.getUProfile().get("lang"))+ arrField[0]+" table = "+tableName);
									}
									if (ftype.equalsIgnoreCase("integer")
											|| ftype.equalsIgnoreCase("double")
											|| ftype.equalsIgnoreCase("float")
											|| ftype.equalsIgnoreCase("long"))
										filter += arrField[1] + "="
												+ this.getString(arrField[0]);
									else
										filter += arrField[1] + "='"
												+ this.getString(arrField[0])
												+ "'";
								}
								String sql = "select count(1) numrows from "
										+ tableName + " where " + filter;
								try {
									boolean found = this.selectDB(sql,tableName);
									if (!found) {
										out = true;
									} else {
										MyLog.error(this,this.getUProfile(),StaticProperties.messagePools.getMessage("MSG0006",	this.getUProfile().get("lang"))+ tableName);
										out = false;
										break;
									}
								} catch (Exception ex) {
									MyLog.error(this, this.getUProfile(), ex);
									out = false;
									break;
								}
							}
						}
					}
				}
			}
		}
		return out;
	}

//	public synchronized int delete() {
	public int delete() {
		return delete("delete");
	}

//	public synchronized int deleteForMyTable() {
	public int deleteForMyTable() {
		return delete("save");
	}

	private int delete(String chk) {
		try {
//			this.addKey(true);
			this.pRemote.setDbRecord(this);
			if (this.keyOK()) {
				if (pRemote.findByPrimaryKey()) {
					StaticProperties.myConnection.beginTransaction(
							this.userPro, this);
					if (this.preDeleteTrigger()) {
						if (this.deleteAllchild()) {
							if (this.chkDependTableAllRelation(chk)) {
								this.saveStatus = 4;
								int i = this.realDelete();
								this.postDeleteTrigger();
								this.clearData();
								StaticProperties.myConnection.endTransaction(
										this.userPro, this);
								return i;
							} else {
								StaticProperties.myConnection.rollback(
										this.userPro, this);
								this.saveStatus = -4;
							}
						} else {
							MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getMessage("MSG0007", this.getUProfile().get("lang")));
							StaticProperties.myConnection.rollback(this.userPro, this);
							this.saveStatus = -4;
						}
					} else {
						MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getMessage(	"MSG0008", this.getUProfile().get("lang")));
						StaticProperties.myConnection.rollback(this.userPro,	this);
					}
				} else {
					MyLog.error(this, this.getUProfile(),
							StaticProperties.messagePools.getMessage("MSG0009",
									this.getUProfile().get("lang")));
					this.saveStatus = -5;
					StaticProperties.myConnection.rollback(this.userPro, this);
				}
			} else {

				MyLog.error(this, this.getUProfile(),StaticProperties.messagePools.getMessage("MSG0010",this.getUProfile().get("lang")));
				this.saveStatus = -88;
				StaticProperties.myConnection.rollback(this.userPro, this);
			}
		} catch (SQLException e1) {
			MyLog.error(this, this.getUProfile(), e1);
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
		}
		return this.saveStatus;
	}

	private int realDelete() throws Exception {
		this.setDeleteBy();
		if (this.isSave)
			this.deleteRecord();
		this.saveStatus = 4;
		return this.saveStatus;
	}

	protected void deleteRecord() throws Exception {
		this.removeFile(false);
		this.pRemote.remove();
	}

	private void clearData() {
		try {
			for (int i = 0; i < this.aField.size(); i++) {
				String field = this.aField.get(i).toString();
				super.set(field, "");
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
		}
	}

	private void clearDataExceptKeyField() {
		try {
			for (int i = 0; i < this.aField.size(); i++) {
				if (!this.allKey.contains(this.aField.get(i).toString())) {
					String field = this.aField.get(i).toString();
					super.set(field, "");
				}
			}
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
		}
	}

	public void setPKObject() {
		try {
			pK = new DataBMPKey();
		} catch (Exception ex) {
			MyLog.error(this, this.getUProfile(), ex);
		}
	}

	public void setMessageError(String mess) {
		this.messageError = mess;
	}

	public void setMessageWarning(String mess) {
		this.messageWarning = mess;
	}

	public String getMessageError() {
		return this.messageError;
	}

	public String getMessageWarning() {
		return this.messageWarning;
	}

	public ChildManager getParent() {
		return (ChildManager) this.parentTable;
	}
	
	public void setParent(ChildManager ch) {
		try {
			this.parentTable= ch;
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
		}
	}

	private void saveLog(String fieldName, String oldValue, String cuValue) {
		try {
			if (this.getUProfile() != null ) {
				if (this.dbEventLog == null) {
					this.dbEventLog = new InitialRecord(this.getUProfile())
							.getDbRecord("leventlog");
					this.dbEventLog.setColumn("*");
				} else {
					this.dbEventLog.clearField();
				}
				this.dbEventLog.set("companyid", this.getString(this
						.getNameKey(String.valueOf(this.getSizeKey()))));
				this.dbEventLog.set("table_name", this.getTableName());
				this.dbEventLog.set("field_name", fieldName);
				this.dbEventLog.set("refer", this.getRunNo());
				this.dbEventLog.set("old_value", oldValue);
				this.dbEventLog.set("new_value", cuValue);
				this.dbEventLog.set("user_code", this.getUProfile().getEmployee());
				this.dbEventLog.save();
			}
		} catch (Exception ex) {
			MyLog.error(this, this.getUProfile(), ex);
		}
	}

	public void actionLog() {
	}

	protected String decryption(String encryption) {
		try {
			Base64Decoder b = new Base64Decoder(encryption);
			return b.processString();
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			return null;
		}
	}

	public void actionLog(FieldManager fm) {
		boolean islog;
		islog = fm.isLog();
		if (islog) {
			String cuValue, oldValue, nameField;
			nameField = fm.getName();
			
			oldValue = fm.getOriginalData();
			cuValue = this.getString(nameField);
			if (fm.isModified()) {
				this.saveLog(nameField, oldValue, cuValue);
			}
		
		}
	}

	public void setEncryptOn() {
		this.encrypt = true;
	}

	public void setEncryptOff() {
		this.encrypt = false;
	}

	public String getSystemCode(String table, String field) {
		try {
			ChildManager ch = this.getChild(table);
			DbRecord dbrec = null;
			if (ch instanceof DbRecord) {
				dbrec = (DbRecord) ch;
			} else if (ch instanceof DbInquiry) {
				dbrec = ((DbInquiry) ch).getCurrentDbRecord();
			} else if (ch instanceof DbTable) {
				dbrec = ((DbTable) ch).getCurrentRecordManager();
			}
			MyLog.debug(this, this.getUProfile(), " :::   PROPERTY FIELD : "
					+ dbrec.getField(field).getProperty("validcode"));
			MyLog.debug(this, this.getUProfile(),
					" :::   getSystemCode : Child : " + ch + "  Fieldname : "
							+ field);
			String key = ch.getString(field);
			MyLog.debug(this, this.getUProfile(), "this.getFiled(" + field
					+ ").getProperty(validcode):   " + this.getField(field));
			String validCode = dbrec.getField(field).getProperty("validcode");
			MyLog.debug(this, this.getUProfile(),
					" ::::::::::::::: validcode :  " + validCode);
			String lang = this.userPro.get("lang");
			String value = "", tmpKey = "";
			this.setValidCode(validCode, lang);
			for (int point = 0; point < sysCode.length; point++) {
				tmpKey = sysCode[point][0];
				value = sysCode[point][1];
				if (tmpKey.equals(key))
					return value;
			}
			return "";
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			return "";
		}
	}

	public String getSystemCode(String field) {
		try {
			String key = this.getString(field);
			String validCode = this.getField(field).getProperty("validcode");
			String lang = this.userPro.get("lang");
			String value = "", tmpKey = "";
			this.setValidCode(validCode, lang);
			for (int point = 0; point < sysCode.length; point++) {
				tmpKey = sysCode[point][0];
				value = sysCode[point][1];
				if (tmpKey.equals(key)) {
					return value;
				}
			}
			return "";
		} catch (Exception ex) {
			MyLog.error(this, this.getUProfile(), ex);
			return "";
		}
	}

	private void setValidCode(String validCode, String lang) {
		if ((validCode != null) && (lang != null)) {
			String[][] sysC = SystemCode.getContent(validCode);
			this.sysCode = new String[sysC.length][2];
			for (int point = 0; point < sysC.length; point++) {
				sysCode[point][0] = new String(sysC[point][0]);
				sysCode[point][1] = new String(sysC[point][1]);
				if (sysC[point][1].indexOf(",") > 0) {
					if (lang.equalsIgnoreCase("eng")) {
						sysCode[point][1] = new String(sysC[point][1]
								.substring(0, sysC[point][1].indexOf(",")));
					} else {
						sysCode[point][1] = new String(sysC[point][1]
								.substring(sysC[point][1].indexOf(",") + 1));
					}
				}
			}

		}
	}

	public int assignField(DataSet rs) {
		String tmpField="";
		this.rReferLangOff();
		int ok = 0;
		try {
			if (rs.isEmpty()) {
				ok = 0;
				this.foundData = false;
			} else {
				FieldManager fm=null;
				for (int i = 0; i < this.aField.size(); i++) {
					tmpField = this.aField.get(i).toString();
					fm=this.getField(tmpField);

					tmpField = fm.getName();
					String value = (String) rs.getString(tmpField);
					String type = fm.getType();
					if (value == null) {
						if (type.equalsIgnoreCase("integer")
								|| type.equalsIgnoreCase("double")
								|| type.equalsIgnoreCase("bigdecimal")
								|| type.equalsIgnoreCase("long")
								|| type.equalsIgnoreCase("float")){
							value = "0";
						}else{
							value = "";
						}

						if(fm.isEncrypt()){
							value=new Base64Encoder(value).processString();
						}					
						
					}
					if (value == null) {
						value = "";
					} else {
						value = this.charCode("point4", value);
					}
					if (fm != null) {
						ok = 1;
						fm.setOriginal(value);
					}
				}
				this.foundData = true;
				this.setLastUpdate();
			}
			if (this.referLang){
				this.rReferLangOn();
			}else{
				this.rReferLangOff();
			}
			return ok;
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			if (e instanceof NullPointerException){
				if (rs != null){
					MyLog.error(this, this.getUProfile(),"RecordCmp0 assignField() - HaveError");
				}
			}
			return 0;
		}
	}

	public void editCheckOn() {
		editCheck = "true";
	}

	public void editCheckOff() {
		editCheck = "false";
	}

	public String getFieldNotSave() {
		return this.fieldNotSave;
	}

	public String getAutoNumber(String field) {
		DbInquiry di = new InitialInquiry(this.userPro).getDbInquiry();
		try {
			di.initMyTable(this.getTableName(), "", "");
			di.setColumn(field);
			di.setFilter(this.getKeyFilter());
			di.refresh();
			di.next();
			String data = di.getString(field);
			di.closeConnection();
			return data;
		} catch (Exception e) {
			try {
				MyLog.error(this, this.getUProfile(), e);
				di.closeConnection();
			} catch (Exception ex) {
				MyLog.error(this, this.getUProfile(), ex);
			}
			return "";
		}
	}

	private Hashtable getChildClone() {
		Hashtable child = new Hashtable();
		Enumeration em = this.getChildTable().keys();
		while (em.hasMoreElements()) {
			String key = (String) em.nextElement();
			Object ch = this.getChildTable().get(key);
			if (ch instanceof DbRecord) {
				DbRecord db;
				try {
					db = (DbRecord) ((DbRecord) ch).cloneRecord(true);
					child.put(key, db);
				} catch (Exception e) {
					child.put(key, ch);
				}

			} else {
				child.put(key, ch);
			}
		}
		return child;
	}

	public DbRecord cloneRecord(boolean isSave) {
		DbRecord db = null;
		try {
			if (isSave)
				db = new InitialRecord(this.userPro).getDbRecord(this.actualName);
			else
				db = new InitialRecord(this.userPro).getDbRecord(this.actualName, 'i');
			db.loadHelp(true);
			db.setColumn(this.getArrayFieldList());
			for (int i = 0; i < this.aField.size(); i++) {
				String fieldName = this.aField.get(i).toString();
				String data = this.getString(fieldName);
				db.set(fieldName, data);
			}
			db.setRelationInfo(this.getRelationInfo());
			// db.setChildTable(this.getChildTable());
			db.setChildTable(this.getChildClone());
			db.setParam(this.getParam());
		} catch (RemoteException e) {
			MyLog.error(this, this.getUProfile(), e);
		}
		return db;
	}

	/**
	 * Returns the referOn.
	 * 
	 * @return boolean
	 */
	public boolean isReferOn() {
		return referOn;
	}

	/**
	 * Sets the referOn.
	 * 
	 * @param referOn
	 *                  The referOn to set
	 */
	public void setReferOn(boolean referOn) {
		this.referOn = referOn;
	}

	protected boolean preInsertTrigger() throws Exception {
		return true;
	}

	protected boolean preUpdateTrigger() throws Exception {
		return true;
	}

	protected boolean preDeleteTrigger() throws Exception {
		return true;
	}

	protected void postInsertTrigger() throws Exception {
		// processworkflow();
	}

	protected void postUpdateTrigger() throws Exception {
		// processworkflow();
	}

	protected void postDeleteTrigger() throws Exception {
	}

	protected boolean checkChildTable() {
		return true;
	}

	private void processworkflow() throws Exception {
		if (this.wfOn && this.wfActive()) {
			// try {
			UProfile up = this.userPro;
			HashMap paramWorkflow = (HashMap) this.param.clone();
			paramWorkflow.put("uprofile", up);
			paramWorkflow.put("runno", this.getRunNo());
			paramWorkflow.put("up_tname", this.getActualName());
			paramWorkflow.put("up_fname", "wfstatus");
			String  refkey=up.getEmployee()+"$"+this.getString(this.documentno)+"$"+paramWorkflow.get("step_id");
			if (this.wfkey.length() > 0) {
				if (!this.wfkey.equalsIgnoreCase("runno"))
					paramWorkflow.put("wfkey", this.getString(this.wfkey));
				else
					paramWorkflow.put("wfkey", this.getRunNo());
			}
			if (this.documentno != null && !this.documentno.equals("")) {
				paramWorkflow.put("document_no", this.getString(this.documentno));
			}
			
			GenProcessQuque gp=new GenProcessQuque();
			if(!this.isDup){
				gp.createWorkFlowProcess(up, paramWorkflow,"creat Workflow ["+this.getString(this.documentno)+"]", "ҧ͡ ["+this.getString(this.documentno)+"]", "", "",refkey);
			}else{
				gp.createWorkFlowProcess(up, paramWorkflow,"approve Workflow ["+this.getString(this.documentno)+"]", "͹ѵ͡ ["+this.getString(this.documentno)+"]", "", "",refkey);
			}
			
		}
	}

	public void setWFOn() {
		this.wfOn = true;
	}

	public void setWFOff() {
		this.wfOn = false;
	}

	protected void preProcessWf() {
		if (!this.wfActive()) {
			if (this.getField("wf_status") != null) {
				// pae edit ���� WF_STATUS=6 ����ͧ Update Status (������
				// 6=HR Edit)
				if (!this.getString("wf_status").equals("6")) {
					this.set("wf_status", 4);
				}
			}
		}
	}

	public void postInqNext() {
	}

	public int recCount() {
		return 1;
	}

	// select db direct to dataset
	private boolean selectDB(String sql, String tableName) throws Exception {
		boolean result = false;
		DataSet ds = new DataSet(sql, this.getUProfile().getDbName(), tableName);
		try {
			ds.initConnection(this.getUProfile());
			if (ds.hasEror()) {
				MyLog.error(this, this.getUProfile(), " ------ Check DB SQL : "+ sql);
				throw new Exception(ds.msgError());
			} else{
				if(ds.next()){
//					result = !ds.getString("numrows").equals("0");
					result = !ds.getString(0).equals("0");
				}
			}
			ds.closeConnection();
		} catch (SQLException e) {
			MyLog.error(this, this.getUProfile(), sql);
			MyLog.error(this, this.getUProfile(), e);
			result = true;
		} catch (RemoteException e) {
			MyLog.error(this, this.getUProfile(), sql);
			MyLog.error(this, this.getUProfile(), e);
			result = true;
		}
		return result;
	}

	public void afterLoadConfig() {
	}

	private void stampTimeChange() {
		UProfile uf = this.getUProfile();
		String dbName = uf.getDbName();
		String companyid = uf.get("companyid");
		String key = dbName + "-" + companyid + "-" + this.tableName;
		StaticProperties.timeLoadPData.put(key.toLowerCase(), String
				.valueOf(new CscCalendar().getTime()));
	}

	public void searchOriginal() {
		this.setCompany();
		try {
			this.referLangOff();
			this.pRemote.setDbRecord(this);
			pRemote.findByPrimaryKey();
		} catch (Exception e) {
			MyLog.info(this,	this.getUProfile(),"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Search data not found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		}
	}

	public int putChild(ChildManager oChild) {
		int check = super.putChild(oChild);
		try {
			oChild.setParent((ChildManager) this);
		} catch (RemoteException e) {
			MyLog.error(this, this.getUProfile(), e);
		}
		return check;
	}

	public void setAllDeleteLevel(String delete) {
		Hashtable re = this.getRelationInfo();
		Enumeration em = re.keys();
		Vector chNew = new Vector();
		while (em.hasMoreElements()) {
			Relation relation = (Relation) re.get(em.nextElement());
			if (relation.getDeleteLevel().equalsIgnoreCase("99"))
				relation.setDeleteLevel(delete);
		}
	}

	private void setDeleteBy() {
		CscCalendar cs = new CscCalendar();
		this.set("delete_date", cs.getYYYYMMDD());
		this.set("delete_time", cs.getHHMMSS());
		this.set("delete_by", this.userPro.getUserId());
	}

	private void setCreateBy()  {
		try{
			CscCalendar cs = new CscCalendar();
			this.set("create_date", cs.getYYYYMMDD());
			this.set("create_time", cs.getHHMMSS());
			this.set("create_by", this.userPro.get("employeeid"));
			this.set("actorid", this.getUProfile().get("actorid"));
			this.getUProfile().setFieldConfig((DbRecord) this);
			this.set("edit_date", cs.getYYYYMMDD());
			this.set("edit_time", cs.getHHMMSS());
			this.set("edit_by", this.userPro.get("employeeid"));
			FieldManager fm = this.getField("runno");
			fm.set(fm.insAutoNumber());
		}catch(Exception ex){
			MyLog.error(this,this.getUProfile(),ex);
			this.saveStatus = -1;
		}
	}

	private void setEditBy() {
		CscCalendar cs = new CscCalendar();
		this.set("edit_date", cs.getYYYYMMDD());
		this.set("edit_time", cs.getHHMMSS());
		this.set("edit_by", this.userPro.get("employeeid"));
		if(this.getString("wf_ref_doc").length()==0){ /* edit by pas 20111129 ͧҡ wf_ref_doc  field system óշաúѹ֡ҡ˹ҨҤ  isduplicate ӡ setҨҡ database  ֧ӡ setҨҡ premote ᷹*/
			try {
				this.set("wf_ref_doc",pRemote.getString("wf_ref_doc"));
			} catch (Exception e) {
				MyLog.error(this,this.getUProfile(),e);
			}
		}
	}

	public int getConfirmStatus() {
		return this.saveStatus;
	}

	public boolean isSaveState() {
		return this.saveState;
	}

	public MyHashMap getMyHashMap() {
		MyHashMap h = new MyHashMap();
		for (int i = 0; i < this.aField.size(); i++) {
			String temp = this.aField.get(i).toString();
			FieldManager fm = this.getField(temp);
//			FieldManager fm = this.getField(i);			
			h.put(temp, fm.getString());
		}
		return h;
	}

	public DbRecord clone() {
		RecordCmp0 O = null;
		try {
			O = (RecordCmp0) super.clone();
			O.mf = this.mf.clone((DbRecord) this);
			O.pRemote = new DataBMPBean();
			O.pRemote.setDbRecord(O);
			// O.key = this.key.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return (DbRecord) O;
	}

	public DbRecord clone(UProfile upf) {
		RecordCmp0 O = null;
		try {
			O = (RecordCmp0) super.clone();
			if (!this.appname.equalsIgnoreCase(upf.get("appname").toString())
					|| !this.language.equalsIgnoreCase(upf.get("lang")
							.toString())) {
				O.mf.setUProfile(upf);
				O.mf = this.mf.clone((DbRecord) this, upf);
			} else {
				O.mf.setUProfile(upf);
				O.mf = this.mf.clone((DbRecord) this);
			}
			O.pRemote = new DataBMPBean();
			O.pRemote.setDbRecord(O);
			O.pRemote.clearOldWhere();
			O.referLangOff();
			// O.key = this.key.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return (DbRecord) O;
	}

	public PropertyRec clonePropertyRec(UProfile upf) {
		PropertyRec O = null;
		if (!this.appname.equalsIgnoreCase(upf.get("appname").toString())
				|| !this.language.equalsIgnoreCase(upf.get("lang").toString())) {
			O = this.mf.clone((DbRecord) this, upf);
		} else {
			O = this.mf.clone((DbRecord) this);
		}
		return O;
	}

	public void setPropertyRec(PropertyRec pr) {
		this.mf = pr;
	}
	
	public void refresh() {
		this.pRemote.setDbRecord(this);
		super.refresh();
	}

    public void configInq() {
    }  
        
    /**
	 * @author James
	 * źź record  update 
     *  ѧ
	 */
	protected int  removeFile(boolean isUpdate){
		int count=0;
		/*
		String path =	"";
		FieldManager fm = null;
//		InitialEnvironment env = new InitialEnvironment("GLOBAL");
		for (Iterator it = mf.keySet().iterator(); it.hasNext();) {
			try {
				fm = (FieldManager) mf.get(it.next());
				if(("fileupload").equalsIgnoreCase(fm.getComType())) {

//					String upload = fm.getProperty("upload");
//					String folder = fm.getProperty("folder");
					String fValue = fm.getString();
					String oValue = fm.getOldValue();
//					String alternate =  fm.getProperty("alternate");
					String uploadField = fm.getParent().getTableName() +"." +fm.getName();

//					if( upload != null && (!upload.equals("")) ) {
//						path = env.getValue( upload +"-dir");
//						if( folder !=null && (!folder.equals("")) ) {
//							path += folder;
//						}
//					}

					if( isUpdate ) {
						// in case update record
						if( !(oValue.equals("")) && !(oValue.equalsIgnoreCase(fValue)) ) {
							
							// when old_value != "" and old_value != alternate and old_value != new_value
							//FileUploadUtils.deleteFileUpload(uploadField, null, oValue);
//							File file = new File(path, oValue);
//							MyLog.info(this,this.getUProfile(), "Field '" +fm.getName() +"' was update, file has been delete :" +file.getCanonicalPath());
//							if( file.delete() ) {
//								count++;
//							}
						}
					} else {
						// in case delete recore
						if( !fValue.equals("")) {
							
							// when new_value != "" and new_value != alternate
//							File file = new File(path, fValue);
//							MyLog.info(this,this.getUProfile(), "Field '" +fm.getName() +"' was update, file has been delete :" +file.getCanonicalPath());
//							if( file.delete() ) {
//								count++;
//							}
							//FileUploadUtils.deleteFileUpload(uploadField, null, fValue);
						}
					}
				}
			} catch (Exception e){
				MyLog.error(this, this.getUProfile(), e);
			}
		}*/
		return  count;
	}
	
	/**
	 * require project CscFileUtils
	 * @author james
	 */
	public String getViewUrl(String field) {
		String url ="";
		try {
			FieldManager fm = this.getField(field);
			if(("fileupload").equalsIgnoreCase(fm.getComType())){
				
				FileDownloadUtils2 utils = new FileDownloadUtils2();
				utils.setUploadField(fm.getParent().getTableName(), fm.getName() );
				utils.setFilename( this.getString(field) );
				url = utils.getViewUrl();
			}
			return url;

		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			return "";
		}
	}
	
	/**
	 * require project CscFileUtils
	 * @author james
	 */
	public String getDownloadUrl(String field) {
		String url ="";
		try {
			FieldManager fm = this.getField(field);
			if(("fileupload").equalsIgnoreCase(fm.getComType())){
				
				FileDownloadUtils2 utils = new FileDownloadUtils2();
				utils.setUploadField(fm.getParent().getTableName(), fm.getName() );
				utils.setFilename( this.getString(field) );
				url = utils.getDownloadUrl();
			}
			return url;
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			return "";
		}
	}
	
	/**
	 * 
	 * require project CscFileUtils
	 * @author james
	 */
	public String getZipUrl(String field){
		String url ="";
		try {
			FieldManager fm = this.getField(field);
			if(("fileupload").equalsIgnoreCase(fm.getComType())){
				
				FileDownloadUtils2 utils = new FileDownloadUtils2();
				utils.setUploadField(fm.getParent().getTableName(), fm.getName() );
				utils.setFilename( this.getString(field) );
				url = utils.getZipdUrl();
			}
			return url;
		} catch (Exception e) {
			MyLog.error(this, this.getUProfile(), e);
			return "";
		}
	}
   
	protected void finalize() throws Throwable {
		//this.closeConnectionChild(this.getChildTable());
	}
	
	/**
	 * @author odragonfireo
	 * @param target = table ͧźͧ initial Record зӡ set ͹
	 * @param filter = ͹䢷ͧ¢ 稨зӡź table source 
	 */
	public void moveToTable(DbRecord target,String filter,boolean sort) {
		int countExp=0;
		try{
		StaticProperties.myConnection.beginTransaction(this.userPro, this);
		if(this.getArrayFieldList().size()==target.getArrayFieldList().size()){
			this.pRemote.setDbRecord(this);		
			countExp+=this.pRemote.moveToTable(target, filter,sort);
			String deleteSql="delete from "+this.getTableName();
			if(filter.trim().length()>0){
				deleteSql+=" where "+filter;
			}
			countExp+=this.pRemote.deleteTable(deleteSql);
		}else{
			MyLog.error(this,this.getUProfile(),"Field not match source["+this.getArrayFieldList().size()+"] but target["+this.getArrayFieldList().size()+"]");
			StaticProperties.myConnection.rollback(this.userPro, this);
		}
		if(countExp==0){
			StaticProperties.myConnection.endTransaction(this.userPro, this);
		}else{
			StaticProperties.myConnection.rollback(this.userPro, this);
		}
	   }catch(Exception ex){
		   try {
			StaticProperties.myConnection.rollback(this.userPro, this);
		} catch (SQLException e) {}
	   }
	}
	
	/**
	 * @author odragonfireo
	 * @param sql = query 㹡¢
	 * @param deleteSql = query ͧźtable 鹷ҧѧҡ¢º
	 */
	public void moveToTable(String sql,String deleteSql) {
		int countExp=0;
		try{
			StaticProperties.myConnection.beginTransaction(this.userPro, this);
			this.pRemote.setDbRecord(this);
			countExp+=this.pRemote.moveToTable(sql);
			countExp+=this.pRemote.deleteTable(deleteSql);
			if(countExp==0){
				StaticProperties.myConnection.endTransaction(this.userPro, this);
			}else{
				StaticProperties.myConnection.rollback(this.userPro, this);
			}
		}catch(Exception ex){
			MyLog.error(this,this.getUProfile(),"Cloud n't moveToTable not match sql["+sql+"] deleteSql["+deleteSql+"]");
			try {
				StaticProperties.myConnection.rollback(this.userPro, this);
			} catch (SQLException e) {}
		}
	}

	public String getObjectTrace() {
		StringBuilder build=new StringBuilder();
		/**
		 * 
		 * comment by pas  
		 * comment ͷͺ memory
		 * 
		 * 		
		build.append("====RecordCmp0.toString()=").append(getClass().getName() + "@" + Integer.toHexString(hashCode()));
		build.append("isDup =").append(isDup).append("\n");
		build.append("obk =").append(obk).append("\n");
		build.append("now =").append(now).append("\n");
		build.append("confirm =").append(confirm).append("\n");
		build.append("messageError =").append(messageError).append("\n");
		build.append("messageWarning =").append(messageWarning).append("\n");
		build.append("encrypt =").append(encrypt).append("\n");
		build.append("referOn =").append(referOn).append("\n");
		build.append("fieldName =").append(fieldName).append("\n");
		build.append("oValue =").append(oValue).append("\n");
		build.append("newValue =").append(newValue).append("\n");
		build.append("keyGroup =").append(keyGroup).append("\n");
		build.append("vUpdateData =").append(vUpdateData).append("\n");
		build.append("saveStatus =").append(saveStatus).append("\n");
		build.append("fieldNotSave =").append(fieldNotSave).append("\n");
		build.append("keyLink =").append(keyLink).append("\n");
		build.append("wfOn =").append(wfOn).append("\n");
		build.append("saveState =").append(saveState).append("\n");
		build.append("dbEventLog =").append(dbEventLog).append("\n");
		build.append("transfer =").append(transfer).append("\n");
		build.append("=====================");
		**/
		return build.toString();
	}

	public void setWFTransferOff() {
		this.wfTransfer=false;
	}

	public void setWFTransferOn(String wf_ref_doc) {
		this.wfTransfer=true;
		this.wfRefDoc=wf_ref_doc;		
	}
	
	public boolean getWFTransfer() {
		return this.wfTransfer;
	}
	
	public String getWFRefDoc() {
		return this.wfRefDoc;
	}
	
	protected void initWFTransfer(){
		if(this.getWFTransfer()&&this.getWFRefDoc().length()>0){	
			this.set("wf_ref_doc",this.getWFRefDoc());
		}
	}
	
	public String getWorkflowURL(){
		String url="#";
		String wf_ref_doc=this.getString("wf_ref_doc");
			if(wf_ref_doc.length()>0){
				String sql="select actor_url from actor_parameter where wf_seq_no in (select runno from workflow_data where doc_no='"+wf_ref_doc+"') order by step_seq_no desc, actor_seq_no desc,step_id";
				DataSet ds=new DataSet(sql,this.getUProfile().getDbName(),"actor_parameter");
				try {
					ds.initConnection(this.getUProfile());
					if(ds.next()){
						url=ds.getString("actor_url");
					}
				} catch (Exception e) {
					MyLog.error(this,this.getUProfile()," Can't getWorkflowURL >> "+e.getMessage());
				}finally{
					if(ds!=null){
						ds.closeConnection();
					}
				}
			}
		return url;
	}
	
TongZuu committed
1925
}