<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="price_adjust.aspx.cs" Inherits="bps.bps.price_adjust" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="../javascript/jquery-1.12.4.min.js"></script>

         <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" /> 
     <script src="../bootstrap/js/bootstrap.min.js"></script>

     
    <style>
        ul,li{
             list-style-type:none

        }
    </style>

</head>
<body style="font-size:12px; margin:10px;">
    <form id="form1" runat="server">
    <div style="margin:10px;">
    <b>调整子件产品价格或者数量</b>
    </div>


        <style>

.table-head table,.table-body table{width:100%;}

.table-head{ background-color:#999;color:#ffffff;   width:1020px}

.table-head   th {
             padding:10px;
             margin:10px;
             text-align:left;
              border:solid 1px #000;
               border-collapse:collapse;
            }



 

.table-body table tr:nth-child(2n+1){background-color:#f2f2f2;}


 .table-body td{
             padding:10px;
             margin:10px;
              text-align:left;
              border:solid 1px #000;
               border-collapse:collapse;
            }

        </style>

        
    
       

    
      
       <div class="table-head" >
       <table style="table-layout:fixed"> 
          

     <tr>                       
                                    <th width="60px">ID</th> 
                                   <th width="110px">ItemCode</th> 
                                    <th width="300px">ItemName</th>                                  
                                    <th width="100px"> Quantity</th>
                                    <th width="120px" >Price</th>
                                    <th width="120px">Total </th> 
                                    <th width="80px">Currency</th>
                                    <th   >汇率</th>

                              </tr>

         
     </table>
     </div>



<div   style="width:1020px; height:500px; overflow:scroll">
         
  <div  class="table-body">
                <asp:Repeater runat="server" ID="rpt_items" DataSourceID="sds">
                    <HeaderTemplate>
                          <table style="table-layout:fixed"> 

                    </HeaderTemplate>

                    <ItemTemplate>

                        
                           
                                 <tr>
                                       <td width="60px">
                                         <%#Eval("id") %>
                                     </td>

                                     <td width="110px">
                                         <div style="width:90px">
                                         <%#Eval("itemcode") %>
                                            </div>
                                     </td>

                                      <td  width="300" >
                                          <div style="width:280px">
                                         <%#Eval("itemname") %>
                                              </div>
                                     </td>

                                     <td width="100px">
                                      

                        <input type="text" value='<%#Eval("quantity") %>' class="quantity" style="width:70px" />
                                         

                                     </td>


                                         <td width="120px">
                                      

                        <input type="text" value='<%#Eval("price") %>' class="price"  style="width:70px"/>
                                         

                                     </td>

                                       <td width="120px">
                                         
                                           <span class="total"> 
                                               <%# (float.Parse(Eval("price").ToString()) * float.Parse(Eval("quantity").ToString()) ).ToString("N2")   %>
                                           </span>

                                     </td>


                                           <td  width="80px" >
                                      
<span class="currency">
    <%#Eval("currency") %>
</span>
                        
                                        
                                                

                                     </td>


                                     <td   >

                                         <span class="rate">
    <%#Eval("rate") %>
</span>
         

                                     </td>
                                   

                                 </tr>

                           

                          
                    </ItemTemplate>


                    <FooterTemplate>
                          </table>

                    </FooterTemplate>


                </asp:Repeater>
               
        
   
    </div>




</div>
            



     <div style="width:1000px; font-weight:bold; margin:10px; text-align:right">

    
        原料价格: <span id="total_price" style=" display:inline-block; color:red; font-weight:bold" > </span><b style="color:red">RMB</b>
         &nbsp;&nbsp;
         BOM价格: <span id="bom_price" style=" display:inline-block; color:red; font-weight:bold"></span><b style="color:red">RMB</b>
&nbsp;&nbsp;<a href="###" class="btn btn-success btn-sm" onclick="save();">保存</a>
         </div>



        <script>


            $(".quantity").change(
                function ()
                {
                   var _quantity = $(this).val();
                   var _price= $(this).parent().parent().find(".price:eq(0)").val();
                   var _total = parseFloat((_quantity * _price).toFixed(2));
                   
                   $(this).parent().parent().find(".total:eq(0)").html(_total);
                   CalTotal();

                } );




            $(".price").change(
           function () {
               var _quantity = $(this).val();
               var _price = $(this).parent().parent().find(".quantity:eq(0)").val();
               var _total = parseFloat((_quantity * _price).toFixed(2));

               $(this).parent().parent().find(".total:eq(0)").html(_total);

               CalTotal();

           });




            function CalTotal()
            {
                var sum = 0;
                $(".table-body tr").each(
                     function () {
                         var _price = $(this).find(".price:eq(0)").val();
                         var _quantity = $(this).find(".quantity:eq(0)").val();
                         var _rate = $(this).find(".rate:eq(0)").html();
                          
                         
                         var _t=_price * _quantity * _rate;
                      
                          

                         sum += _t;

                     });
                
                $("#total_price").html( parseFloat(sum.toFixed(2)));
                    

                calBom(); 

            }


         function   calBom()
            {
                var _s= parseFloat($("#total_price").html())+parseFloat(_workprice *  _workhour);
              
                var _p=_s * ( 100+   _mgrrate  + _profitrate  +  _adjustrate);

                 
                _p = _p / 100.0;

                $("#bom_price").html(_p.toFixed(2)); 

            }


            function save()
            {
                var bid=<%=Request.QueryString["id"] %>;
                var id = "";
                var price = "";
                var quantity = "";
                $(".table-body tr").each(
                     function () {
                         var _id = parseInt($(this).find("td:eq(0)").html());
                         var _price = $(this).find(".price:eq(0)").val();
                         var _quantity = $(this).find(".quantity:eq(0)").val();
                         
                         id += _id + "$";
                         price += _price + "$";
                         quantity += _quantity + "$";

                         

                     });

                
                $.ajax({
                    url: "price_adjst_save.aspx",
                    data: {id:id, price:price, quantity:quantity,bid:bid },
                    type: "post",
                    cache: false,
                    async: false,
                    success: function () {
                        alert("保存成功");
                    }




                });
            
            }












            CalTotal();
        </script>












          <asp:SqlDataSource runat="server" ID="sds"


         ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
               
         SelectCommand="
              
              select * from
(
SELECT  
Id,
ItemCode,
ItemName,
Manufacturer,
quantity,
Price,
Currency
FROM  purchase_quote_items  where quoteid=@id
) A 

inner join 
(
SELECT  paramname, types,rate   FROM purchase_param where types='currency'
)B on A.Currency=B.paramname

" 
         
        >

        <SelectParameters>
            <asp:QueryStringParameter Name="id" QueryStringField="id" DefaultValue="4" /> 
        </SelectParameters>
       


        

    </asp:SqlDataSource>











 







    </form>
</body>
</html>
