<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.system.*" %>
<%@ include file="/sessionInfo.jsp"%>
<%
    //获取提交的参数
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
%>
<form name="formHidden" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
</form>
<%
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    boolean flag = true;
    String sUrl = "index.jsp";
        
    String chkId[] = request.getParameterValues("chkId");
    int iLen = 0;
    if (chkId != null) {
    	iLen = chkId.length;
    }
    //,客户号,  客户名称, 组织机构代码,住所在, 法定代表人,客户联系人,ID    ,本人ID,本人部门ID,本人姓名,本人部门
    //"XXMC21","XXMC2","XXMC11", "XXMC4","XXMC5" ,"XXMC7" ,"XXMC1",XXMC16,XXMC17,XXMC22,XXMC23,
    String sTable = "BD_spdb_customer_company";
    String field_str[] = {"XXMC21","XXMC2","XXMC11","XXMC4","XXMC5","XXMC7","XXMC1","XXMC16","XXMC17","XXMC22","XXMC23","SZOA_BDGSID","SZOA_BDID","SZOA_BDDLID"};
    String value_str[] = null;
    String sKey = "XXMC21";
    String sCond = "";

	SzDataReader dataReader = new SzDataReader();
	SzDataWriter dataWriter = new SzDataWriter();
    String cust_id = "";
    String cust_cn_name = "";
    String org_no = "";
    String office_addr = "";
    String linker_name1= "";
    String linker_name3= "";    
    boolean flagE = false;
    value_str = new String[14];
	value_str[7] = "" + iDLID_SESSION;
	value_str[8] = "" + iBMID_SESSION;
	value_str[9] = "'" + sDLXM_SESSION + "'";
	value_str[10] = "'" + sBMMC_SESSION + "'";
	value_str[11] = "0";
	value_str[12] = "1384";
	value_str[13] = "0";
    
    for (int i =0; i<iLen; i++) {
    	cust_id = SzConvert.strWriteData(request.getParameter("cust_id" + i));
    	cust_cn_name = SzConvert.strWriteData(request.getParameter("cust_cn_name" + i));
    	if (cust_id.equals("") || cust_cn_name.equals("") ) {
    		continue;
    	}
    	
    	org_no = SzConvert.strWriteData(request.getParameter("org_no" + i));
    	office_addr = SzConvert.strWriteData(request.getParameter("office_addr" + i));
    	linker_name1 = SzConvert.strWriteData(request.getParameter("linker_nameA" + i));
    	linker_name3 = SzConvert.strWriteData(request.getParameter("linker_nameB" + i));
    	
    	value_str[0] = "'" + cust_id + "'";
    	value_str[1] = "'" + cust_cn_name + "'";
    	value_str[2] = "'" + org_no + "'";
    	value_str[3] = "'" + office_addr + "'";
    	value_str[4] = "'" + linker_name1 + "'";
    	value_str[5] = "'" + linker_name3 + "'";
    	value_str[6] = "" + SzKey.getInstance().genNextKey(sTable);

    	//是否存在，存在修改，否则增加
    	sCond = sKey + "='" + cust_id + "'";    	
    	flagE = dataReader.isExist(sTable, sCond);
    	if (flagE) {
    		dataWriter.update(sTable, field_str, value_str, sCond);
    	} else{
    		dataWriter.add(sTable, field_str, value_str);
    	}
    }
	dataWriter.close();
    if (flag) {
        out.println(SzPageHelp.jsAlert("操作成功"));
        //out.println(SzPageHelp.jsGoUrl(sUrl));
        out.println(SzPageHelp.jsFormSubmit("formHidden",sUrl));
    } 
%>
