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






        <style>
        table.add th {
         font-weight:normal; text-align:right
        }
            table.table-sm th {
             text-align:left !important; font-weight:bold
            }
    </style> 

 

    <script src="../UserControl/supply_js.aspx?index=1&id=<%=id %>"></script>

   <script src="../javascript/suggest/bootstrap-suggest.min.js"></script>


   

             <asp:Panel runat="server" ID="pnl_rotate">
                
                 <div style="display:none">

               
    <asp:TextBox runat="server" ID="proid"    ></asp:TextBox>
 <asp:TextBox runat="server" ID="sname"    ></asp:TextBox>
 <asp:TextBox runat="server" ID="scode"   ></asp:TextBox>
  </div>


   <table class="table add table-condensed"    >
                    
        <tr>
              <th  width="100px" >物料名称<font color=red>*</font>：</th>
            <td width="200px">
              
 <div class="input-group" style="width:240px;">                   
  <asp:TextBox class="form-control"   ValidationGroup="Add" ID="mname" Text=""  
       style="width:240px;margin-right:0px" runat="server"></asp:TextBox>                             
                   
                      
    <div class="input-group-btn" style="width:1px;">                                                    
     <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
    </div>       
                                              
</div>
            

           </td>

          <th  width="100px" >物料号<font color=red>*</font>：</th>
            <td width="200px">
                <asp:TextBox class="form-control"   ReadOnly="true"  ID="mcode" Text=""  runat="server"></asp:TextBox>
          
               <asp:RequiredFieldValidator runat="server" ID="rfcode" ControlToValidate="mcode" 
                    ErrorMessage="必须填写物料号"
                     ValidationGroup="add"> 

               </asp:RequiredFieldValidator>
                 
                </td>

          

             <th  width="100px" >交货期(天)：</th>
            <td width="200px">
                <asp:TextBox class="form-control"  Text="0"    ID="leadtime"    runat="server"></asp:TextBox>
           </td> 

        </tr>



        <tr>
          <th  width="100px" >价格<font color=red>*</font>：</th>
            <td width="200px">
                 
               <asp:TextBox id="price" Runat="Server"  Text="0"   style="display:inline-block; width:150px"  class="form-control inline"  ValidationGroup="Add"></asp:TextBox> 
 
    <asp:DropDownList runat="server"  style="display:inline-block; width:100px" 
           AppendDataBoundItems="true"   class="form-control inline"   ID="ddl_currency"> 
    </asp:DropDownList>  

           </td>

            <th  width="100px" >最低购买量：</th>
            <td width="200px">
                <asp:TextBox class="form-control"   value="0"  ID="minnum" Text=""  runat="server"></asp:TextBox>
           </td>

             <th  width="100px" >最低购买量量：</th>
            <td width="200px">
               <asp:TextBox class="form-control"   value="99999"  ID="maxnum" Text=""  runat="server"></asp:TextBox>
           </td> 

        </tr>




        <tr>
          <th  width="100px" >报价有效期 从：</th>
            <td width="200px">
                <asp:TextBox class="form-control" onclick="laydate();"   ValidationGroup="Add" ID="dt_pricedatefrom" Text=""  runat="server"></asp:TextBox>
           </td>

            <th  width="100px" >到：</th>
            <td width="200px">
                <asp:TextBox class="form-control  "  onclick="laydate();"  ValidationGroup="Add" ID="dt_pricedateto" Text=""  runat="server"></asp:TextBox>
           </td>

          <th  width="100px" >  </th>
            <td width="200px">
                <asp:TextBox class="form-control"  Visible="false"  ValidationGroup="Add" ID="supplyproname" Text=""  runat="server"></asp:TextBox>
           </td>
        </tr>


        <tr>
            

            <th  width="100px" >供应商内部料号：</th>
            <td width="200px">
                <asp:TextBox class="form-control"   ValidationGroup="Add" ID="supplyprocode" Text=""  runat="server"></asp:TextBox>
           </td>

          
            <th>
             运输方式
            </th>
            <td>

    <asp:DropDownList runat="server" 
       class="form-control  "   ID="ddl_shipmethod"> 
    </asp:DropDownList>  
            </td>







             <th>价格说明</th>
            <td>

                <asp:TextBox class="form-control"   ValidationGroup="Add" ID="note" Text=""  runat="server"></asp:TextBox>
            </td>



        </tr>


       <tr>
           <td colspan="6" align="center">

                  <asp:Button runat="server" ID="btn_add"
                       ValidationGroup="add"
                       Text="添加" CssClass="btn btn-primary btn-sm" OnClick="btn_add_Click" />
           </td>
       </tr>
    </table>


    </asp:Panel>


    <script>
        $("#mname").bsSuggest({
            inputWarnColor: 'rgba(255,255,255)',
            indexId: 1, //data.value 的第几个数据，作为input输入框的内容
            indexKey:0, //data.value 的第几个数据，作为input输入框的内容
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: false, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            effectiveFields: ["name", "code","proid"],
            effectiveFieldsAlias: { name: "物料名", code: "物料号",proid:"ID" },
            showHeader: true,
            url: 'ajax/get_supply_by_name.aspx?t=fromsupply&name=', /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/

            processData: function (json) {
                // url 获取数据时，对数据的处理，作为 getData 的回调函数                
                var i, len, data = { value: [] };
                if (!json || json.length == 0) {
                    return false;
                }
                len = json.length;

                for (i = 0; i < len; i++) {
                    data.value.push({
                        "name": json[i].name,
                        "code": json[i].code,
                        "proid":json[i].proid
                    });
                }

                return data;
            }

        }).on('onSetSelectValue', function (e, keyword, data) {
            
            $("#mcode").val(keyword.id);
            $("#proid").val(data.proid);
        });
           </script>






















    


    <asp:GridView ID="GridView1" runat="server"
         CssClass="table table-hover" GridLines="None"
         AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> 
            <asp:BoundField DataField="code" ReadOnly="true" HeaderText="物料号" SortExpression="code" HeaderStyle-Width="150px" />
            <asp:BoundField DataField="catname"  ReadOnly="true" HeaderText="物料名" SortExpression="catname" HeaderStyle-Width="180px"/>
            <asp:BoundField DataField="price" HeaderText="价格" SortExpression="price" HeaderStyle-Width="80px"/>
            <asp:BoundField DataField="currency" HeaderText="货币" SortExpression="currency" HeaderStyle-Width="60px"/>
            <asp:BoundField DataField="minnum" HeaderText="最低数量" SortExpression="minnum" HeaderStyle-Width="60px"/>
            <asp:BoundField DataField="maxnum" HeaderText="最高数量" SortExpression="maxnum" HeaderStyle-Width="60px"/>
            <asp:BoundField DataField="leadtime" HeaderText="交货期" SortExpression="leadtime" HeaderStyle-Width="80px"/>
            <asp:BoundField DataField="shipmethod" HeaderText="运输方式" SortExpression="shipmethod" HeaderStyle-Width="80px"/>
            <asp:BoundField DataField="supplyprocode" HeaderText="内部料号" SortExpression="supplyprocode" HeaderStyle-Width="80px"/>
             <asp:BoundField DataField="pricedatefrom" HeaderText="有效期从" SortExpression="pricedatefrom"  DataFormatString="{0:yyyy-MM-dd}" HeaderStyle-Width="80px"/>
            <asp:BoundField DataField="pricedateto" HeaderText="有效期到" SortExpression="pricedateto"  DataFormatString="{0:yyyy-MM-dd}" HeaderStyle-Width="80px"/>
            <asp:BoundField DataField="note" HeaderText="价格说明" SortExpression="note" HeaderStyle-Width="200px"/>
        </Columns>
        </asp:GridView>



    <asp:SqlDataSource ID="SqlDataSource1"
         ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
         runat="server" 
       
         DeleteCommand="DELETE FROM [purchase_supply_product] WHERE [id] = @id" 
              
         SelectCommand="
        SELECT 
purchase_supply_product.id, 
purchase_supply_product.proid, 
purchase_categories.catname,
purchase_categories.code,
purchase_supply_product.price,
purchase_supply_product.currency,
purchase_supply_product.minnum,
purchase_supply_product.maxnum, 
purchase_supply_product.leadtime, 
purchase_supply_product.shipmethod,
purchase_supply_product.supplyprocode, 
purchase_supply_product.supplyproname, 
purchase_supply_product.pricedatefrom, 
purchase_supply_product.pricedateto,
purchase_supply_product.note 
FROM purchase_supply_product
left join purchase_categories on proid=purchase_categories.id
 where scode=@scode  ORDER BY purchase_supply_product.id DESC " 

        UpdateCommand="UPDATE [purchase_supply_product] SET   
        [price] = @price, [currency] = @currency, [minnum] = @minnum, [maxnum] = @maxnum,
         [leadtime] = @leadtime, [shipmethod] = @shipmethod, [supplyprocode] = @supplyprocode, 
         [pricedatefrom] = @pricedatefrom, [pricedateto] = @pricedateto,
         [note] = @note WHERE [id] = @id">
      
        
        
          <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
       
        
         <SelectParameters>
             <asp:ControlParameter  Name="scode"  ControlID="scode" />
        </SelectParameters>


        <UpdateParameters>
             <asp:Parameter Name="id" Type="Int32" />
            <asp:Parameter Name="proid" Type="Int32" /> 
            <asp:Parameter Name="price" Type="Decimal" />
            <asp:Parameter Name="currency" Type="String" />
            <asp:Parameter Name="minnum" Type="Decimal" />
            <asp:Parameter Name="maxnum" Type="Decimal" />
            <asp:Parameter Name="leadtime" Type="String" />
            <asp:Parameter Name="shipmethod" Type="String" />
            <asp:Parameter Name="supplyprocode" Type="String" /> 
            <asp:Parameter Name="pricedatefrom" Type="DateTime" />
            <asp:Parameter Name="pricedateto" Type="DateTime" />
            <asp:Parameter Name="note" Type="String" />
           
        </UpdateParameters>
        </asp:SqlDataSource>










</asp:Content>
