<!--#include file="../Include/Const.Asp" -->
<!--#include file="../Include/ConnSiteData.Asp" -->
<!--#include file="../CheckAdmin.Asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../Images/Admin_style.css">
<script language="javascript" src="../JavaScript/Admin.js"></script>
<script language="javascript" src="../JavaScript/select_date.js"></script>
<%
'If InStr(session("GroupPurview"), "|2,") = 0 Then
    'response.Write ("<br /><br /><div align=""center""><font style=""color:red; font-size:9pt; "")>您没有管理该模块的权限！</font></div>")
    'response.End
'End If
Dim Result
Result = request.QueryString("Result")
Dim ID,ch_name,ch_kehuname,ch_kehuID,ch_amount,ch_MemName,ch_RealName,ch_memo,ch_addtime,ch_modytime,ch_status

ID = request.QueryString("ID")
ch_kehuname=trim(request.QueryString("ch_kehuname"))
Call MychancesEdit()
%>
<br />
<script language="javascript">
function chancesedit(){
if (document.editForm.ch_name.value.replace(/^\s*/g,"")=="") {
    alert("机会名称不能为空,请认真填写!");
    document.editForm.ch_name.focus();
    return false;
 }
}
</script>
<table class="tableBorder" width="95%" border="0" align="center" cellpadding="5" cellspacing="1">
  <form name="editForm" method="post" action="?Action=SaveEdit&Result=<%=Result%>&ID=<%=ID%>" onSubmit="return chancesedit()">
    <tr>
      <td class="forumRowHighlight">
	  <table width="100%" border="0">
  <tr>
    <td width="70" valign="top"><img src="../Images/chances_1.png" /></td>
    <td valign="middle">
	<font style="font-size:18px; font-weight:bold;"><%If Result = "Add" then%>添加<%ElseIf Result = "Modify" then%>编辑<%End If%>机会</font>
	
	
	</td>
  </tr>
</table>
	  
	  </td>
    </tr>
	<tr>
      <td class="forumRowHighlight">
	 
	  
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border"><tr class="tdbg"><td valign="top">
  <table width="100%" align="center" cellpadding="2" cellspacing="1">
  <tbody id="Tabs" style="display:">
  <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight"><input name="MemName" type="hidden" id="MemName" style="width: 120;background-color:#EBF2F9" value="<%=session("UserName")%>" maxlength="16" <%response.write ("readonly")%>>
	  <input name="RealName" type="hidden" id="RealName" style="width: 120;background-color:#EBF2F9" value="<%=genjinText(session("UserName"))%>" maxlength="16" <%response.write ("readonly")%>></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">联系人：</td>
      <td class="forumRowHighlight"><input name="ch_kehuname" type="text" id="ch_kehuname" style="width:120" value="<%=ch_kehuname%>" maxlength="50">
      <font class="redy"></font> 
	  &nbsp;输入联系人姓名或公司名称（并从下拉提示列表中选取一个）</td>
	</tr>
	
	<tr>
      <td align="right" class="forumRow">机会名称：</td>
      <td class="forumRowHighlight"><input name="ch_name" type="text" id="ch_name" style="width: 280" value="<%=ch_name%>" maxlength="249"> 
      <font class="redy">*</font> </td>
    </tr>
        
	<tr>
      <td align="right" class="forumRow">金额：</td>
      <td class="forumRowHighlight"><input name="ch_amount" type="text" id="ch_amount" style="width: 120" value="<%=ch_amount%>" maxlength="16"> 
      （<font class="redy">元</font>）</td>
    </tr>
    <tr>
      <td align="right" class="forumRow" valign="top">机会描述或背景信息： </td>
      <td class="forumRowHighlight">
	    <textarea name="ch_memo" cols="50" rows="8" id="ch_memo" style="width: 480"><%=ch_memo%></textarea></td>
    </tr>
    
  </tbody>

  </table>
</td>
</tr>
</table>
	  </td>
    </tr>
    	
    <tr>
      <td class="forumRowHighlight" align="center"><input name="submitSaveEdit" type="submit" id="submitSaveEdit" value="保存"> <input type="button" value="返回上一页" onclick="history.back(-1)"></td>
    </tr>
  </form>
</table>

<%
Sub MychancesEdit()
    Dim Action, rs, sql,rs2,sql2
    Action = request.QueryString("Action")
    If Action = "SaveEdit" Then
        Set rs = server.CreateObject("adodb.recordset")
		Set rs2 = server.CreateObject("adodb.recordset")
        If Result = "Add" Then
            
    '判断是否输入联系人-----------------------
		if Trim(Request.Form("ch_kehuname"))<>"" then
			'#查找对应联系人
			sql2 = "select * from Zqj_Kehu where (Company='"&Trim(Request.Form("ch_kehuname"))&"' and class=1 and MemName='"&session("UserName")&"') or (Cname='"&Trim(Request.Form("ch_kehuname"))&"' and class=2 and MemName='"&session("UserName")&"')"
            rs2.Open sql2, conn, 1, 3
			if rs2.bof and rs2.eof then
			   ch_kehuID=0
			else
			   ch_kehuID=rs2("ID")
			end if
			ch_kehuname=Trim(Request.Form("ch_kehuname"))
            rs2.Close
            Set rs2 = Nothing
			'#查找对应联系人结束
		else
			ch_kehuname=""
			ch_kehuID=0
		end if
			
	'判断是否输入联系人结束---------------------
            sql = "select * from Zqj_chances"
            rs.Open sql, conn, 1, 3
            rs.addnew
            rs("ch_MemName") = Trim(Request.Form("MemName"))
            rs("ch_RealName") = Trim(Request.Form("RealName"))
			rs("ch_name")=StrReplace(Trim(Request.Form("ch_name")))
			rs("ch_kehuname")=ch_kehuname
			rs("ch_kehuID")=ch_kehuID
			if Trim(Request.Form("ch_amount"))<>"" and IsNumeric(Trim(Request.Form("ch_amount"))) then
			   rs("ch_amount")=Trim(Request.Form("ch_amount"))
			else
			   rs("ch_amount")=0
			end if
			rs("ch_memo")=Trim(Request.Form("ch_memo"))
			rs("ch_addtime")=now()
			rs("ch_modytime")=now()
			rs("ch_status")="C"
			ID=rs.Fields("ID")
            rs.update
            rs.Close
            Set rs = Nothing
			response.Redirect("My_chancesView.Asp?Result=Modify&ID="&ID)
        End If
        If Result = "Modify" Then
		'判断是否输入联系人-----------------------
			if Trim(Request.Form("ch_kehuname"))<>"" then
			'#查找输入的对应联系人
			sql2 = "select * from Zqj_Kehu where (Company='"&Trim(Request.Form("ch_kehuname"))&"' and class=1 and MemName='"&session("UserName")&"') or (Cname='"&Trim(Request.Form("ch_kehuname"))&"' and class=2 and MemName='"&session("UserName")&"')"
            rs2.Open sql2, conn, 1, 3
			if rs2.bof and rs2.eof then
			   ch_kehuID=0
			else
			   ch_kehuID=rs2("ID")
			end if
			ch_kehuname=Trim(Request.Form("ch_kehuname"))
            rs2.Close
            Set rs2 = Nothing
			'#查找输入的对应联系人
			else
			    ch_kehuname=""
			    ch_kehuID=0
			end if
		'判断是否输入联系人结束---------------------
            sql = "select * from Zqj_chances where ID="&ID
            rs.Open sql, conn, 1, 3
            'rs("ch_MemName") = Trim(Request.Form("MemName"))
            'rs("ch_RealName") = Trim(Request.Form("RealName"))
			rs("ch_name")=StrReplace(Trim(Request.Form("ch_name")))
			rs("ch_kehuname")=ch_kehuname
			rs("ch_kehuID")=ch_kehuID
			if Trim(Request.Form("ch_amount"))<>"" and IsNumeric(Trim(Request.Form("ch_amount"))) then
			   rs("ch_amount")=Trim(Request.Form("ch_amount"))
			else
			   rs("ch_amount")=0
			end if
			rs("ch_memo")=Trim(Request.Form("ch_memo"))
			rs("ch_modytime")=now()
           rs.update
           rs.Close
           Set rs = Nothing
		   response.Redirect("My_chancesView.Asp?Result=Modify&ID="&ID)
           			
        End If

    Else
        If Result = "Modify" Then
            Set rs = server.CreateObject("adodb.recordset")
            sql = "select * from Zqj_chances where ID="& ID
            rs.Open sql, conn, 1, 1
			if rs.bof and rs.eof then
			response.Write "<script language='javascript'>alert('参数错误！');history.back(-1);</script>"
			response.End
			else
		   ch_name=rs("ch_name")
		   ch_kehuname=rs("ch_kehuname")
		   ch_kehuID=rs("ch_kehuID")
		   ch_amount=rs("ch_amount")
		   ch_MemName=rs("ch_MemName")
		   ch_RealName=rs("ch_RealName")
		   ch_memo=rs("ch_memo")
		   ch_addtime=rs("ch_addtime")
		   ch_modytime=rs("ch_modytime")
		   ch_status=rs("ch_status")
			end if
            rs.Close
            Set rs = Nothing
        End If
    End If
End Sub


Function genjinText(MemName)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Members where MemName='"&MemName&"'"
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	genjinText="无跟进人"
	else
    genjinText = rs("RealName")
	end if
    rs.Close
    Set rs = Nothing
End Function
%>