<%@ page language="C#" autoeventwireup="true" inherits="general_Contract_AddClientProduct, CrmCommand" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
     <script  src="../../Javascript/Trim.js" type="text/javascript">
    </script>
    <script src="../../Javascript/formCheck.js" type="text/javascript"></script>
    <script language=javascript type="text/javascript">
     var  j=0;
     var nount=0;
     var n=0;
    function PriceResult()
    {
		    var Types=document.getElementById("DropProName");
		    var index=Types.selectedIndex;
		    var productprice = Types.options[index].value;
		  
		    PageMethods.ProductSingPrice(productprice,callback);
    }
    function callback(result)
    {
       document.getElementById("TxtSingPrice").innerText=result;
    }
    function Totals()
    {
    	var prices=document.getElementById("TxtSingPrice").value;//数量
    	if(!isMath(TrimStr(prices)))
    	{
    	    alert('您输入的单价必须是数字!'); 
    	    return false;
    	}
    	 var Nummber=document.getElementById("TxtProNum").value;//数量
    	  if(Trim(Nummber))
    	  {
    	      if(isMath(Nummber))
    	      {
    	          var price=document.getElementById("TxtSingPrice").value;//单价
	              var Types=document.getElementById("DropPeriod");
		          var index=Types.selectedIndex;
		          var period = Types.options[index].value;//年限
	             // var Total=parseFloat(price.value)*parseInt(period)*parseInt(Nummber.value);
	              PageMethods.ProductTotals(price,period,Nummber,CallBackTotals);
	              //document.getElementById("TxtSmallPrice").innerText=Total;
	          }
	          else
	          {
	            alert('您输入的数量格式不正确!');
	            return false;
	          }
    	    
    	  }
    	 else
    	 {
    	   alert('数量不能为空!');
    	   return false;
    	 }
    
	    
    }
    function CallBackTotals(Result)
    {
     document.getElementById("TxtSmallPrice").innerText=Result;
    }
    function add()
    {
		//将数据插入表格数
		if(confirm('你确认要把产品加入合同列表中去!'))
		{
		        var cpnum=document.getElementById("TxtProNum");//数量
		        var prices=document.getElementById("TxtSmallPrice").value;//总价
		        var pis=document.getElementById("TxtSingPrice").value;//单价
    	        if(!isMath(TrimStr(pis)))
    	        {
    	            alert('您输入的单价必须是数字!'); 
    	            return false;
    	        }
	            if(!isMath(TrimStr(prices)))
	            {
	                alert('您输入的总价必须是数字!'); 
	                return false;
	            }
		         if(Trim(cpnum.value))
    	         {
    	           if(isMath(cpnum.value))
    	           {
		                var Types=document.getElementById("DropProName");
		                var index=Types.selectedIndex;
		                var productname = Types.options[index].text;//产品名称
		                var cpdj=document.getElementById("TxtSingPrice");//单价
		                var op= Math.round(cpdj.value)
		                //var cpsl=document.getElementById("Numbers");//年限
		                var dropperiod=document.getElementById("DropPeriod");
		                var indexs=dropperiod.selectedIndex;
		                var cpsl = dropperiod.options[indexs].value;//年限
		                var cpxj= document.getElementById("TxtSmallPrice");// 总价
		                var zj=Math.round(cpxj.value);
		                var cpbz=document.getElementById("TxtRemark");//产品说明
		                var yj=document.getElementById("DropForEver");//是否永久
		                var sy=yj.selectedIndex;
		                var seyj=yj.options[sy].text;
		                var content=document.getElementById("layer1").innerHTML;
		                j=j+1;
		                n=j;
		                content=content+"<table id=\"tb"+j+"\" class=\"small\" cellSpacing=\"1\" cellPadding=\"1\"  border=\"0\" bgcolor=#000000 style=\"width: 766px\"><TR>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 45px; height: 21px;\"><input class=\"SmallButton\" id=\"Chk"+j+"\" type=\"checkbox\" /></TD>"
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 96px\">"+productname +"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 45px\">"+op+"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 45px\">"+cpsl+"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 72px\">"+cpnum.value+"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 72px\">"+zj+"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 72px\">"+seyj+"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 374px\">"+cpbz.value+"</TD>";
		                content=content+"<TD class=\"TableData\" style=\"WIDTH: 72px\"><INPUT class=\"SmallButton\" onclick=\"Del();\" type=\"button\" value=\"删除\"></TD></TR></table>";
		                document.getElementById("layer1").innerHTML=content;  
		            }
		           else
	               {
	                    alert('您输入的数量格式不正确!');
	                    return false;
	               }
		         }
		         else
    	         {
    	            alert('数量不能为空!');
    	            return false;
    	         }
		        
		}
	}
   function Del()
   {
     for(var c=1;c<=j;c++)
     {
       var Check="Chk"+c;
       var tbs="tb"+c;
       var dd=document.all[Check];
       if(typeof(dd)!="undefined")
       {  
             if(document.all[Check].checked)
             {
                  n--;
                 document.all[tbs].deleteRow(0);
             } 
       }
       
     }
   }
   
    function OnSucceeded()
    {
     
         for(var i=1;i<=j;i++)
          {
  　         var tbb="tb"+i;
  　          var dh=document.all[tbb].rows.length;
      　      if(dh==1)
      　      {
 　              var productname=document.all[tbb].rows[0].cells[1].innerText;//产品名称
   　            var productdj=document.all[tbb].rows[0].cells[2].innerText;//产品单价
   　            var period=document.all[tbb].rows[0].cells[3].innerText;//产品年限
   　            var num=document.all[tbb].rows[0].cells[4].innerText;//产品数量
   　            var sum=document.all[tbb].rows[0].cells[5].innerText;//产品小计
   　            var yjs=document.all[tbb].rows[0].cells[6].innerText;//产品是否永久
   　            var Remark=document.all[tbb].rows[0].cells[7].innerText;//产品说明
   　            PageMethods.InsertConProduct($get('HidCon').value,yjs,productname,num,period,Remark,productdj,sum,ConCallBack) 
   　        }
          } 
    }
    function ConCallBack(Result)
    {
             nount++;
             var p= document.getElementById("Hidnum").value;
             var i =parseInt(Result)+parseInt(j);
             if(i==1)
	   　    {
	   　       p=1;
	   　       document.getElementById("Hidnum").value=p;
	   　      
	   　       
	   　    }
	   　    else
	   　    {
	   　       if(i==0)
	   　       {
	   　        alert('录入失败!');
	   　       }
	   　     
	   　    }
	   　    if(nount==n)
	   　    {
	   　       alert('您已经成功为您的客户增加了合同的相关产品');
	   　       self.close();
	   　    }
    }
    </script>
    <base target=_self></base>
</head>
<body class ="bodycolor" leftmargin="0" topmargin="0">
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods=true>
        </asp:ScriptManager>
    <div>
        <fieldset align="left" style="width: 753px">
            <legend>合同产品信息 </legend>
            <table align="center" bgcolor="#000000" border="0" cellpadding="1" cellspacing="1"
                class="small" style="width: 766px">
                <tr>
                    <td class="TableData" style="width: 69px; height: 19px">
                        产品名称</td>
                    <td class="TableData" style="width: 51px; height: 19px">
                        单价 (元)</td>
                    <td class="TableData" style="width: 44px; height: 19px">
                        数量
                    </td>
                    <td class="TableData" style="width: 62px; height: 19px">
                        年限
                    </td>
                    <td class="TableData" style="width: 59px; height: 19px">
                        小计 (元)</td>
                    <td class="TableData" style="width: 66px; height: 19px">
                        是否永久
                    </td>
                    <td class="TableData" style="width: 161px; height: 19px">
                        产品说明
                    </td>
                </tr>
                <tr>
                    <td class="TableData" style="width: 69px; height: 19px">
                        <asp:DropDownList ID="DropProName" runat="server" CssClass="BigInput" onclick="PriceResult()">
                        </asp:DropDownList></td>
                    <td class="TableData" style="width: 51px; height: 19px">
                        <asp:TextBox ID="TxtSingPrice" runat="server" CssClass="BigInput" Width="77px"></asp:TextBox>
                    </td>
                    <td class="TableData" style="width: 44px; height: 19px">
                        <asp:TextBox ID="TxtProNum" runat="server" CssClass="BigInput" Width="51px"></asp:TextBox>
                    </td>
                    <td class="TableData" style="width: 62px; height: 19px">
                        <asp:DropDownList ID="DropPeriod" runat="server" onclick="return Totals()">
                            <asp:ListItem>1</asp:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                            <asp:ListItem>3</asp:ListItem>
                            <asp:ListItem>4</asp:ListItem>
                            <asp:ListItem>5</asp:ListItem>
                            <asp:ListItem>6</asp:ListItem>
                            <asp:ListItem>7</asp:ListItem>
                            <asp:ListItem>8</asp:ListItem>
                            <asp:ListItem>9</asp:ListItem>
                            <asp:ListItem>10</asp:ListItem>
                        </asp:DropDownList></td>
                    <td class="TableData" style="width: 59px; height: 19px">
                        <asp:TextBox ID="TxtSmallPrice" runat="server" CssClass="BigInput" Width="58px"></asp:TextBox>
                    </td>
                    <td class="TableData" style="width: 66px; height: 19px">
                        <asp:DropDownList ID="DropForEver" runat="server">
                            <asp:ListItem>否</asp:ListItem>
                            <asp:ListItem>是</asp:ListItem>
                        </asp:DropDownList></td>
                    <td class="TableData" style="width: 161px; height: 19px">
                        <asp:TextBox ID="TxtRemark" runat="server" CssClass="BigInput" Width="283px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="center" class="TableData" colspan="7" style="height: 19px">
                        <input id="Button3" class="SmallButton" onclick="return add()" type="button" value="提交产品" />
                        <input id="Button1" class="SmallButton" type="button" value="确认无误" onclick= "OnSucceeded()" /></td>
                </tr>
                <tr>
                    <td class="TableData" colspan="7" style="height: 19px">
                        <table align="center" bgcolor="#000000" border="0" cellpadding="1" cellspacing="1"
                            class="small" style="width: 766px">
                            <tr>
                                <td class="TableData" style="width: 45px; height: 21px">
                                    <font face="宋体">选择</font></td>
                                <td class="TableData" style="width: 96px; height: 21px">
                                    <font face="宋体">产品名称</font></td>
                                <td class="TableData" style="width: 45px; height: 21px">
                                    <font face="宋体">单价</font></td>
                                <td class="TableData" style="width: 45px; height: 21px">
                                    <font face="宋体">年限</font></td>
                                <td class="TableData" style="width: 45px; height: 21px">
                                    <font face="宋体">数量</font></td>
                                <td class="TableData" style="width: 72px; height: 21px">
                                    小计</td>
                                <td class="TableData" style="width: 72px; height: 21px">
                                    是否永久</td>
                                <td align="center" class="TableData" style="width: 374px; height: 21px">
                                    产品说明
                                </td>
                                <td class="TableData" style="width: 72px; height: 21px">
                                    删除</td>
                            </tr>
                        </table>
                        <div id="layer1" runat="server">
                            <input class="SmallButton" onclick="Del();" type="button" value="全删" /></div>
                    </td>
                </tr>
            </table>
        </fieldset>
        <input id="Hidnum" type="hidden" value="0" />
        <input id="HidCon" type="hidden" runat=server /></div>
    </form>
</body>
</html>
