<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.sql.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.formAppend.*" %>
	<!-- ------
	主合同公共表字段		授信业务表字段	关联ID=50
	
	BD_spdb_hetong			BD_spdb_limit
	//S1XXMC1				L1XXMC1		主键
	S1XXMC5				L1XXMC5		主合同号
	S1XXMC3				L1XXMC6		币别
	S1XXMC6				L1XXMC7		金额
	S1XXMC7				L1XXMC9		额度管理费
	S1XXMC8				L1XXMC25	授信期限
	S1XXMC10			L1XXMC14	授信固定日期
	S1XXMC11			L1XXMC16	合同签订日
	S1XXMC18			L1XXMC26	到期方式

	------------------------------------------客户管理
	BD_CUSTOMER_SOFT_CONTRACT	合同中
	HTXXMC1
	HTXXMC8	金额
	HTXXMC27 已付款	 = HTXXMC27 + YSKXXMC31
	HTXXMC30 未付款  = HTXXMC30 - YSKXXMC31

	BD_CUSTOMER_SOFT_RECEIPTS	已收款
	YSKXXMC1
	YSKXXMC8	未付款金额
	
	------------------------------------------车辆管理
	出车登记、回车登记后直接影响用车申请的状态、车辆信息的状态
	BD_VEHICLE_VEHICLEINFO		车辆
	CLXXXXMC3	车牌
	CLXXXXMC25	车辆使用状态（空闲，已出车）

	BD_VEHICLE_YONGCHESHENQING	申请
	SQXXMC1
	SQXXMC2		车牌号码
	SQXXMC22	状态（申请中，已出车，已收回）

	BD_VEHICLE_YONGCHEJILU	出车	关联ID=16
	JLXXMC1
	JLXXMC2		车牌号码

	BD_VEHICLE_SHOUCHEJILU	回车	关联ID=17
	SCXXMC1
	SCXXMC2		车牌号码	
	------ -->
<%
	//获取提交的参数
	String sType  = SzConvert.toZeroStr(request.getParameter("type"));	//关联的ID
	String sPKEY  = SzConvert.toZeroStr(request.getParameter("PKEY"));	//主表单信息ID
	String sKEY  = SzConvert.toZeroStr(request.getParameter("KEY"));	//主表单信息ID
	String sFormID  = SzConvert.toZeroStr(request.getParameter("FormID"));	//主表单信息ID
	String sOPERATOR  = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));	//主表单信息ID
	
	
	SzDataReader dataReader = null;
	String sTable = "";
	String sField = "";
	String sCond = "";
	String sValue = "";
	ResultSet rs = null;
  SzDataWriter dataWriter = null;
	
  try {
	  if ((sFormID.equals("1384")) && !sKEY.equals("0") && sOPERATOR.equals("ADD") ) {
		//增加学员后，自动增加收费
		net.sz600.drivingSchool.Charge charge = new net.sz600.drivingSchool.Charge();
		charge.addCharge( SzConvert.toInt(sKEY) );
	  } else if ((sFormID.equals("1401")) && !sKEY.equals("0") && (sOPERATOR.equals("ADD") || sOPERATOR.equals("update")) ) {
		//System.out.println("sFormID===" + sFormID);
		//2013-03-16:变更学员状态
		net.sz600.drivingSchool.Student student = new net.sz600.drivingSchool.Student();
		student.changeState( SzConvert.toInt(sKEY) );

	  } else if ((sFormID.equals("1247")) && !sKEY.equals("0")) {
		//System.out.println("发会议通知");
	    	OfficeSupplies officeSupplies = new OfficeSupplies();
		officeSupplies.sendMeetingAlert(SzConvert.toInt(sKEY));
	  } else if ((sFormID.equals("1356")) && !sKEY.equals("0")) {
	    	//资产管理，维修，报废操作。
	    	OfficeSupplies officeSupplies = new OfficeSupplies();
	    	officeSupplies.scrap(SzConvert.toInt(sKEY));
	  } 	  
	  else if ((sFormID.equals("1352")) && !sKEY.equals("0")) {
    	//进货单或者领用,触发函数计算办公用品的库存
    	OfficeSupplies officeSupplies = new OfficeSupplies();
    	officeSupplies.modifyStockIn(SzConvert.toInt(sKEY));
    } 
    else if ((sFormID.equals("1353")) && !sKEY.equals("0")) {
    	OfficeSupplies officeSupplies = new OfficeSupplies();
    	officeSupplies.modifyStockOut(SzConvert.toInt(sKEY));
    }
    else if (sType.equals("12") && !sPKEY.equals("0") && !sKEY.equals("0")) {
		//客户管理，合同下的已收款，回写数据到合同中

		dataReader = new SzDataReader();
		sTable = "BD_CUSTOMER_SOFT_RECEIPTS";
		sField = "YSKXXMC8,YSKXXMC8";
		sCond = "YSKXXMC1 =" + sKEY;
		rs = dataReader.readInfo(sTable, sField, sCond);
		if (rs != null && rs.next()) {			
			//写数据
			StringBuffer sb = new StringBuffer(" ");
			sb.append(" HTXXMC27 = HTXXMC27 + ");
			sb.append(SzConvert.toSpaceStr(rs.getString(1)));
			sb.append(" ,HTXXMC30 = HTXXMC30 - ");
			sb.append(SzConvert.toSpaceStr(rs.getString(2)));

			sValue = sb.toString();
			sb = null;
			rs.close();
			dataReader.closeAll();
			
			dataWriter = new SzDataWriter();			
			sTable = "BD_CUSTOMER_SOFT_CONTRACT";			
			sCond = "HTXXMC1=" + sPKEY;
			dataWriter.update(sTable, sValue, sCond);
			dataWriter.closeAll();
		}
	   } else if (sType.equals("16") && !sPKEY.equals("0") && !sKEY.equals("0")) {
			dataReader = new SzDataReader();
			sTable = "BD_VEHICLE_YONGCHEJILU";
			sField = "JLXXMC2";
			sCond = "JLXXMC1 =" + sKEY;
			rs = dataReader.readInfo(sTable, sField, sCond);
			String temp_16 = "";

			if (rs != null && rs.next()) {
				temp_16 = SzConvert.toSpaceStr(rs.getString(1));

				rs.close();
				dataReader.closeAll();
				
				dataWriter = new SzDataWriter();			
				sTable = "BD_VEHICLE_YONGCHESHENQING";
				sValue = "SQXXMC22='已出车'";
				sCond = "SQXXMC1=" + sPKEY;
				dataWriter.update(sTable, sValue, sCond);
				
				sTable = "BD_VEHICLE_VEHICLEINFO";
				sValue = "CLXXXXMC25='已出车'";
				sCond = "CLXXXXMC3='" + temp_16 + "'";
				dataWriter.update(sTable, sValue, sCond);				
				dataWriter.closeAll();
			}		 
	 } else if (sType.equals("17") && !sPKEY.equals("0") && !sKEY.equals("0")) {
			dataReader = new SzDataReader();
			sTable = "BD_VEHICLE_SHOUCHEJILU";
			sField = "SCXXMC2";
			sCond = "SCXXMC1 =" + sKEY;
			rs = dataReader.readInfo(sTable, sField, sCond);
			String temp_17 = "";
			if (rs != null && rs.next()) {
				temp_17 = SzConvert.toSpaceStr(rs.getString(1));

				rs.close();
				dataReader.closeAll();
				
				dataWriter = new SzDataWriter();			
				sTable = "BD_VEHICLE_YONGCHESHENQING";
				sValue = "SQXXMC22='已收回'";
				sCond = "SQXXMC1=" + sPKEY;
				dataWriter.update(sTable, sValue, sCond);
				
				sTable = "BD_VEHICLE_VEHICLEINFO";
				sValue = "CLXXXXMC25='空闲'";
				sCond = "CLXXXXMC3='" + temp_17 + "'";
				dataWriter.update(sTable, sValue, sCond);				
				dataWriter.closeAll();
			}			 
	 } else if (sType.equals("50") && !sPKEY.equals("0") && !sKEY.equals("0")) {
		
		dataReader = new SzDataReader();
		sTable = "BD_spdb_hetong";
		sField = "S1XXMC5,S1XXMC3,S1XXMC6,S1XXMC7,S1XXMC8,S1XXMC10,S1XXMC11,S1XXMC18";
		sCond = "S1XXMC1=" + sKEY;
		rs = dataReader.readInfo(sTable, sField, sCond);
		if (rs != null && rs.next()) {			
			//写数据
			StringBuffer sb = new StringBuffer("");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(1)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(2)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(3)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(4)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(5)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(6)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(7)));
			sb.append("'");
			sb.append("~");
			sb.append("'");
			sb.append(SzConvert.toSpaceStr(rs.getString(8)));
			sb.append("'");
			sValue = sb.toString();
			sb = null;
			rs.close();
			dataReader.closeAll();
			
			dataWriter = new SzDataWriter();			
			sTable = "BD_spdb_limit";
			sField = "L1XXMC5~L1XXMC6~L1XXMC7~L1XXMC9~L1XXMC25~L1XXMC14~L1XXMC16~L1XXMC26";
			
			sCond = "L1XXMC3='单笔' AND L1XXMC1=" + sPKEY;
			dataWriter.update(sTable, sField, sValue, sCond, "~");
			dataWriter.closeAll();
		}//if end
		
		
	  } //else if ends
    }catch(Exception e) {
    	System.out.println(e);
    }
%>