<%@ Page Title="" Language="C#" MasterPageFile="~/bps/basic.Master" AutoEventWireup="true" CodeBehind="define_quote_price.aspx.cs" Inherits="bps.bps.define_quote_price" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script src="../javascript/layer/layer.js"></script>

    <script src="../javascript/common.js"></script>

    <h4>设计报价单价格</h4>

    <script>

          _id=<%=Request.QueryString["id"]%>;
          _customercode='<%=Request.QueryString["customercode"]%>';


    </script>



    <asp:GridView runat="server" ID="gv_list" CssClass="table table-bordered" ClientIDMode="Static" GridLines="None" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="sds">
        <Columns>
         
           

            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
            <asp:BoundField DataField="ItemCode" HeaderText="ItemCode" SortExpression="ItemCode" />
            <asp:BoundField DataField="ItemName" HeaderText="ItemName" SortExpression="ItemName" /> 
            <asp:BoundField DataField="Manufacturer" HeaderText="Manufacturer" SortExpression="Manufacturer" />
              <asp:BoundField DataField="quantity" HeaderText="quantity" SortExpression="quantity" />

            
            <asp:TemplateField>
                <HeaderStyle Width="90px" />
                <HeaderTemplate>供应商号</HeaderTemplate>
                 <ItemTemplate>
                     <input type="text"  onchange="save('supplycode',<%#Eval("id")%>,this);"  style="width:110px"  value='<%#Eval("supplycode") %>' />
                 </ItemTemplate>
            </asp:TemplateField>

             
            <asp:BoundField DataField="supplyname" HeaderText="供应商名" SortExpression="supplyname" />
          

              
            <asp:TemplateField>
                <HeaderStyle Width="90px" />
                <HeaderTemplate><font >报价价格</font></HeaderTemplate>
                 <ItemTemplate>
                        <input type="text" value="<%#Eval("Price")%>"   style="width:110px" 

                              onchange="save('price',<%#Eval("id")%>,this);"    />

                  
                 </ItemTemplate>
            </asp:TemplateField>

              <asp:TemplateField>
                <HeaderStyle Width="60px" />
                <HeaderTemplate><font >货币</font></HeaderTemplate>
                 <ItemTemplate>
                     <input type="text"  style="width:70px" value='<%#Eval("Currency") %>'   onchange="save('currency',<%#Eval("id")%>,this);" />

                      

                 </ItemTemplate>
            </asp:TemplateField> 


            <asp:TemplateField>
                <HeaderTemplate>供应商数</HeaderTemplate>
                 <ItemTemplate></ItemTemplate>
            </asp:TemplateField>


              <asp:TemplateField>
                <HeaderTemplate>最低价格</HeaderTemplate>
                  <ItemTemplate></ItemTemplate>
            </asp:TemplateField>



              <asp:TemplateField>
                <HeaderTemplate>最近报价价格</HeaderTemplate>
                  <ItemTemplate>
                  </ItemTemplate>
            </asp:TemplateField>


          


        </Columns>
    </asp:GridView>


    <div class="text-center">

    <input type="button" class="btn btn-primary"  onclick="InitCell(); AnaPrice(); LastestPrice(); CompPrice();" value="分析价格"/>

        
    </div>


    <asp:SqlDataSource runat="server" ID="sds"
         ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 


         SelectCommand="SELECT * FROM [purchase_quote_items]  where quoteid=@id"
        

         
        >

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

        </SelectParameters>
       


        

    </asp:SqlDataSource>






    


      <script>

          function save(types, id, text) {
             
              if(types=="supplycode")
              {

                  
                  $.ajax({
                      url: "ajax/ajax_quote.aspx",
                      data: { types: types, id: id, text: escape($(text).val()), t: Math.random() },
                  
                      success: function (data) {
                           
                          $(text).parent().parent().find("td:eq(6)").html(data);

                      }
                  });



              }
              else{
                  $.get("ajax/ajax_quote.aspx", { types: types, id: id, text: escape($(text).val()), t: Math.random() }); 
              }
          }

          function InitCell()
          {
              $("#gv_list tr:not(:first)").each(
                 function () {
                     tds = $(this).find('td');
                     $(tds[9]).html("<img   src=images/loading.gif width=20px> ");
                     $(tds[10]).html("<img src=images/loading.gif width=20px > ");
                     $(tds[11]).html("<img src=images/loading.gif width=20px > ");
                 });
          }



          function AnaPrice()
          {

               



              $("#gv_list tr:not(:first)").each(

                  function () {

                     
                      tds = $(this).find('td');
                      var code = $(tds[1]).html(); 
                   

                      $.ajax({
                          url: "ajax/ana_price.aspx",
                          data: { code:code },
                          cache: false,
                          async: false,  
                          success: function (data) {
                           
                              //var _link=Pop('query_supply_material.aspx?scode=GEER001',1250,650,'查询原料');
                              var _link="<a href=### onclick=Pop('query_supply_material.aspx?scode="+code+"',1250,650,'')>"+data.split('$')[0] +"</a>";
                             $(tds[9]).html(    _link    );                           
                              $(tds[10]).html(data.split('$')[1]);

                          }
                      });

                       

                  } 

                 );

          }











          function LastestPrice()
          {



              $("#gv_list tr:not(:first)").each(

                  function () {


                      tds = $(this).find('td');
                      var code = $(tds[1]).html();


                      $.ajax({
                          url: "ajax/lastest_price.aspx",
                          data: { id:_id, customercode:_customercode,code:code },
                          cache: false,
                          async: false,
                          success: function (data) {

                              $(tds[11]).html(data); 

                          }
                      });



                  }

                 );




          }



          function CompPrice()
          {
          
          
              $("#gv_list tr:not(:first)").each(

                  function () {

                      tds = $(this).find('td');
                      inputs=$(this).find('input');

                      currentprice =  parseFloat(    $(inputs[1]).val()   );
                     
                      minprice = parseFloat($(tds[10]).html()); 
                      lastestprice = parseFloat($(tds[11]).html());



                      if(minprice!=0)
                      {
                          if(currentprice>minprice)
                          {
                              $(tds[10]).html("<font color=red>"+   $(tds[10]).html()   +"</font>");
                          }
                      
                      }


                      if(lastestprice!=0)
                      {
                          if(currentprice>lastestprice)
                          {
                              $(tds[11]).html("<font color=red>"+   $(tds[11]).html()   +"</font>");
                          }
                      
                      }

                  });
                 
          }

    </script>

























</asp:Content>
