<%@ page language="C#" autoeventwireup="true" inherits="Diy_DiyCookie, WebApp_deploy" enableEventValidation="false" %>

<!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">
<link rel="stylesheet" href="css/text.css">
<head>
    <title>自助装机</title>
   
    <link href="css/diy_buy081023.css" rel="stylesheet" type="text/css" />
	<base target="_blank" />
    <style type="text/css">
    .amend {
	BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BACKGROUND: url(../images/diybg.gif) no-repeat 0px -1008px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 41px; COLOR: #000; LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: center; BORDER-RIGHT-WIDTH: 0px
}
    </style>
</head>
<body id="right_frame" style="font-size:12px">
<form   runat="server"  id="form1" >
<input  type="hidden" id="DianNaoId" name="DianNaoId" runat="server" value="125"/>
<!-- DianNaoId是电脑类ID value值一定为整形-->
</form>

    <div class="hack5px">
    </div>
    <div class="right_frame_main">
        <div class="pcbox_1">
            <div class="caption"><span class="left_title"><strong class="l_title">选机方案</strong></span></div>
        </div>
        <div class="hack6px">
        </div>
        <div class="plans">
            <table class="selectedtype" cellspacing="0" cellpadding="0" width="100%" border="0">
                <thead>
                    <tr style="background:#e4eaee">
                        <td valign="middle"  width="35" height="28">选用</td>
                        <td valign="middle"  width="60">&nbsp;配件</td>
                        <td valign="middle"  width="30">数量</td>
                        <td valign="middle"  width="43">单价</td>
                        <td valign="middle"  width="107">品牌型号</td>
                        <td valign="middle"  width="45">添加</td>
                    </tr>
                </thead>
                <tbody id="tbTable">
                <asp:Repeater ID="rpView" runat="server" >
                    <ItemTemplate>
                      <tr onmouseover="style.backgroundColor='#F7F7F7'" onmouseout="style.backgroundColor=''">
                          <td><input type="checkbox" value='<%#Eval("ClassID") %>' /></td>
                          <td><a href='javascript:showId("<%#Eval("ClassID") %>","129")'><%#Eval("ClassName") %></a></td>
                          <td></td>
                          <td></td>
                          <td></td>
                          <td><input class="amend" type="button" onclick="clickEdit(this)" value="添加" /></td>
                      </tr>
                    </ItemTemplate>
                </asp:Repeater>
                </tbody>
            </table>
            <table cellspacing="0" cellpadding="0" width="100%" border="0">
                <tbody>
                    <tr>
                        <td valign="center" align="middle" height="46">
                            <strong class="f16">价格总计：<span class="red2" id="spanCount">0</span>元</strong></td>
                    </tr>
                </tbody>
            </table>
            <div class="subplan">
                 <a href="javascript:AddAction();" id="btnConfirm" target="_self"  >提交方案</a>  <a href="ProjectList.aspx"  target="_blank">预览方案</a> <a target="_blank">使用帮助</a>
            </div>
        </div>
    </div>

    <div class="spanclass">
    </div>
    <script type="text/javascript" src="../Js/jquery/jquery.js"></script>
    <script type="text/javascript">
        function showId(classid,parentId){
            self.parent.showId(classid,parentId);
        }
        function addInPlaylist(classid,name,price){
            $('#tbTable input[type="checkbox"]').each(function(){
                if(this.value==classid){
                    this.checked=true;
                    var obj=$(this).parent().next().next();
                    obj.html(1);
                    obj=obj.next();
                    obj.html(price);
                    
                    obj=obj.next();
                    obj.html(name);
                    
                    GetCount();
                    
                    return;
                }
            });
        }
        function clickEdit(obj){
            var parent=$(obj).parent().prev();
            if(obj.value=="添加"){
                obj.value="提交";

                parent.html( "<input  value='"+parent.html()+"' style='width:70px' />" );
                parent=parent.prev();
                parent.html( "<input  value='"+parent.html()+"' style='width:15px' />" );
                
                parent=parent.prev();
                parent.html( "<input  value='"+parent.html()+"' style='width:15px' />" );
            }
            else{
                obj.value="添加";
                var val=parent.find('input')[0].value;
                if(val=="")val="未定";
                parent.html( val);
                
                parent=parent.prev();
                val=parent.find('input')[0].value;
                if(isNaN(val) || val=="")
                val=0;
                parent.html( val );
                
                parent=parent.prev();
                val=parent.find('input')[0].value;
                if(isNaN(val) || val=="")
                val=1;
                parent.html( val );
                
                parent.prev().prev().find('input')[0].checked=true;
                GetCount();
            }
        }
        
        function GetCount(){
            var count=0;
            var rows=document.getElementById('tbTable').rows;
            for(var i=0;i<rows.length;i++){
                var number=parseInt(rows[i].cells[2].innerHTML);
                var price=parseInt(rows[i].cells[3].innerHTML);
                if(isNaN(number))number=0;
                if(isNaN(price))price=0;
                
                count+=price * number;
            }
            $('#spanCount').html(count);
        }
      
        function AddAction(){  
       
            if($('#spanCount').html()=="0"){
                return alert("你还没有填写表单");
            }
           
           document.getElementById("btnConfirm").innerHTML="请等待...";
           
            var rows=document.getElementById('tbTable').rows;
            var ids="";
            var names="";
            var prices="";
            var numbers="";
            var types="";
            for(var i=0;i<rows.length;i++){  
                    var id=rows[i].cells[0].firstChild.value;
                    var type=rows[i].cells[1].firstChild.innerHTML
                    var number=rows[i].cells[2].innerHTML;
                    var price=rows[i].cells[3].innerHTML;
                    var name=rows[i].cells[4].innerHTML;
                    if(name=="")name="null";
                    if(number=="")number="null";
                    if(price=="")price="null";
                    
                    ids+=id+";";
                    types+=type+";";
                    numbers+=number+";";
                    prices+=price+";";
                    names+=name+";"; 
            }
             
            $('#btnConfirm').attr('href',"javascript:void(0)"); 
            $.post("http://localhost/Diy/ProductAction.aspx",{"ids":ids,"types":types,"numbers":numbers,"prices":prices,"names":names},function(result){
           if(result.length>100)
           {
             alert("请先登录");
             return;
           }
            
            alert("添加成功");
             window.parent.top.location.href='ProductList.aspx?formId='+result ;});
            
            
        }
      </form>  
    </script>
</body>
</html>
