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

    <h1  class="border-active subnav" ><%=isen?"Add / Edit BOM Poduct":"添加/修改 BOM成品" %>   </h1>
 

       <div class=right-action>
        <a href="bom_list.aspx" class="btn btn-primary btn-sm" ><%=isen?"Back":"返回" %>  </a>  
         
    </div>


     <script src="../javascript/suggest/bootstrap-suggest.min.js"></script>
    
    
    <style>
        table.add th {
         font-weight:normal;
        }

           table.table-sm th {
             text-align:left !important; font-weight:bold
            }

            .hdbody {
             overflow:hidden;
            }
    </style>


    

    <div>
     
       <div class="content">
 
            

           <div>



               <asp:Panel runat="server" ID="pnl_rotate">


                   <asp:TextBox runat="server" ID="appname" Visible="false"></asp:TextBox>
                   <asp:TextBox runat="server" ID="appuid" Visible="false"></asp:TextBox>


                   <table class="table table-condensed add" style="margin-bottom: -10px;">

                       <tr>

                           
                           <th width="100px"><%=isen?"Product Name":"成品名称" %> <font color="red">*</font></th>
                           <td width="200px">

                          
                               
                                <div class="input-group"  >                   
  <asp:TextBox class="form-control"   ValidationGroup="Add" ID="productname" Text=""  
       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"><%=isen?"Product Code":"成品编号" %> <font color="red">*</font></th>
                           <td width="200px">
                               <asp:TextBox ID="productcode" runat="Server" class="form-control" ValidationGroup="Add"></asp:TextBox>

                               <asp:RequiredFieldValidator ValidationGroup="Add"
                                   ID="RequiredFieldValidator2" runat="server" ErrorMessage="必须填写成品编号" ControlToValidate="productcode" Display="Dynamic"></asp:RequiredFieldValidator>
                              </td>




                           <th width="100px">
                               <%=isen?"Revision":"版本" %>   <font color="red">*</font>
                           </th>
                           <td width="200px">

                               <asp:TextBox ID="revision" runat="Server" Text="1.0" class="form-control" ValidationGroup="Add"></asp:TextBox>
                               <asp:RequiredFieldValidator ValidationGroup="Add"
                                   ID="RequiredFieldValidator3" runat="server" ErrorMessage="必须填写版本号" ControlToValidate="revision" Display="Dynamic"></asp:RequiredFieldValidator>

                           </td>

                       </tr>






                       <tr>
                           <th><%=isen?"Designer":"设计人" %>     </th>
                           <td>
                               <asp:TextBox class="form-control" ValidationGroup="Add" ID="designname" runat="server"></asp:TextBox>

                           </td>


                           <th>
                               <%=isen?"Design Date":"设计日期" %>   
                           </th>
                           <td>
                               <asp:TextBox class="form-control _dt" ValidationGroup="Add" ID="dt_designdate" runat="server"></asp:TextBox>
                           </td>



                           <th>
                               
                                
                           </th>
                           <td>
                            

                           </td>


                       </tr>






                       <tr>
                           <th><%=isen?"Customer Code":"客户代号" %>    </th>
                           <td>




                               <div class="input-group">

                                   <asp:TextBox class="form-control" onclick="Pop('pop_customer.aspx',950,580,'选择客户');" ValidationGroup="Add" ID="customercode" Text="" runat="server"></asp:TextBox>


                                   <span class="input-group-addon">
                                       <a href="###" onclick="Pop('pop_customer.aspx',950,580,'选择客户'); return false;"><i class="glyphicon glyphicon-user"></i>

                                       </a>

                                   </span>

                               </div>
                               <asp:RequiredFieldValidator runat="server" ValidationGroup="Add" ControlToValidate="customercode" ErrorMessage="必须填写客户简称" ID="rf3" Display="Dynamic"></asp:RequiredFieldValidator>

                           </td>

                           <th>
                               <%=isen?"Customer Name":"客户名称" %> 
                           </th>

                           <td>

                               <asp:TextBox class="form-control" Style="background-color: #ffffff; cursor: not-allowed" ValidationGroup="Add" ID="customername" Text="" runat="server"></asp:TextBox>

                           </td>

                           <th><%=isen?"Product Type":"成品类型" %> </th>
                           <td>
                               <asp:DropDownList runat="server" ID="ddl_producttype" CssClass="form-control"></asp:DropDownList>

                           </td>
                            

                       </tr>









                       <tr>



                           <th>
                               <%=isen?"Struct Drawing 1":"产品结构图1" %>        
                                 
                           </th>
                           <td>
                               <a href="###"
                                   onclick="layer.open({ type:2, content: '../SimlpeUploadFile.aspx?t=customlist&cid=attach1', area: ['700px', '360px'], title:'添加附件'}); return false;"><%=isen?"Upload1":"上传1" %>  </a>

                               <asp:TextBox runat="server" ID="attach1" Style="width: 150px; border: 0px; border-bottom: solid 1px #ccc; display: inline-block"></asp:TextBox>

                               <a href="###" onclick="_preview('attach1');"><%=isen?"Preview1":"预览1" %>    </a>
                           </td>



                           <th>
                               <%=isen?"Struct Drawing 2":"产品结构图2" %>   
                           </th>
                           <td>

                               <a href="###"
                                   onclick="layer.open({ type:2, content: '../SimlpeUploadFile.aspx?t=customlist&cid=attach2', area: ['700px', '360px'], title:'添加附件'}); return false;"><%=isen?"Upload2":"上传2" %>     </a>

                               <asp:TextBox runat="server" ID="attach2" Style="width: 150px; border: 0px; border-bottom: solid 1px #ccc; display: inline-block"></asp:TextBox>

                               <a href="###" onclick="_preview('attach2');"><%=isen?"Preview2":"预览2" %>    </a>

                           </td>

                           <th>

                           </th>
                           <td>
                               <div class="form-control" style="visibility: hidden"></div>

                           </td>

                       </tr>


                       <tr>
                           <th>
                               <%=isen?"Note":"成品说明" %>   
                           </th>
                           <td colspan="3">
                               <asp:TextBox runat="server" ID="note" CssClass="form-control" TextMode="MultiLine" Height="75px"></asp:TextBox>
                           </td>

                       </tr>
                       <tr>

                           <td colspan="4" style="text-align: center">


                               <p style="margin-top:15px;">
                               <asp:Button ID="btn_add" runat="server" Text="添加" ValidationGroup="Add"
                                   class="btn btn-primary btn-flat btn-sm " OnClick="btn_add_Click" />








                               <asp:Button Text="保 存" CssClass="btn btn-success btn-sm" runat="server" ID="edit" ValidationGroup="Add" class="btn-flat btn-sm  btn   bg-green"
                                   OnClick="edit_Click" />

                               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                 <asp:Button Text="删 除" OnClientClick="return confirm('确定删除吗？')" runat="server" ID="delete" CausesValidation="false" class="  btn btn-danger btn-flat btn-sm"
                     OnClick="delete_Click" />

                               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                   
                                       <a href="nextstep.aspx?id=<%=Request.QueryString["id"] %>" class="btn btn-primary btn-sm">提交审批</a>

 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                      <a href="bom_detail.aspx?id=<%=Request.QueryString["id"] %>" class="btn btn-default btn-sm">返回详情</a>

                               </p>

                           </td>
                       </tr>
                   </table>



               </asp:Panel>

          
               
               
               
               
               <asp:Panel runat="server" ID="ph_addscript">

              
                  <script>

                      $("#productname").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","revision","customername","customercode"],
                          effectiveFieldsAlias: { name: "成品名称", code: "成品编号", revision:"版本号", customername:"客户名称", customercode:"客户代号"},
                          showHeader: true,
                          url: 'ajax/get_supply_by_name.aspx?t=frombom&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,
                                      "revision": json[i].revision,
                                      "customername": json[i].customername,
                                      "customercode": json[i].customercode

                                  });
                              }

                              return data;
                          }

                      }).on('onSetSelectValue', function (e, keyword, data) {

                          $("#productcode").val(data.code);
                          $("#revision").val(data.revision);
                          $("#customername").val(data.customername);
                          $("#customercode").val(data.customercode);

                      });
           </script>




              </asp:Panel>
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
                    <script>
                   function _P()
                   { 
                       disablescroll();

                       layer.open({
                           type: 2,
                           title: '选择物料',
                           shadeClose: true,
                           shade: 0.5,
                           area: [1200 + 'px', 600 + 'px'],
                           content: "add_bom_item.aspx?id=<%=Request.QueryString["id"]%>",
                           cancel: function (index) {
                               enablescroll();

                           }
                      });
                   }

                        function _P3()
                        { 
                            disablescroll();

                            layer.open({
                                type: 2,
                                title: '选择物料',
                                shadeClose: true,
                                shade: 0.5,
                                area: [1200 + 'px', 600 + 'px'],
                                content: "add_bom_product.aspx?id=<%=Request.QueryString["id"]%>&proname="+ encodeURI($("#productname").val()),
                                cancel: function (index) {
                                    enablescroll();

                                }
                            });
                        }

         function _P2()
         {

             layer.open({
                 type: 2,
                 title: null,
                 shadeClose: true,
                 shade: 0.5,
                 area: [1250 + 'px', 650 + 'px'],
                 content: "import_bom.aspx?bid=<%=Request.QueryString["id"]%>"
             });
         }
         
               </script>





               <br />
               <br />
               <br />
               <br />



               <div style="border: 0px; padding-bottom: 5px; text-align: right; padding-right: 10px; border-bottom: solid 1px #ccc">

                   <asp:PlaceHolder runat="server" ID="ph_additem" Visible="false">

                       <h4 class="border-active subnav" style="float: left"><%=isen?"Item List":"子件列表" %>   </h4>

                       <a href="###" class="btn btn-danger btn-sm" onclick="_P()"><%=isen?"Add Bom Item":"添加物料" %>    </a>


                         <a href="###" class="btn btn-info btn-sm" onclick="_P3()"><%=isen?"Add Bom Item":"复制物料" %>    </a>


                       <a href="###" class="btn btn-warning btn-sm" onclick="_P2()"><%=isen?"Export Item":"导入物料" %>    </a>

                       &nbsp;&nbsp;|&nbsp;&nbsp;

           <a href="###" class="btn btn-success btn-sm"
               onclick="Pop('copy_bom_1.aspx?bomid=<%=Request.QueryString["id"] %>',600,550,'复制BOM清单')">
               <%=isen?"Copy BOM":"复制BOM成品" %>    </a>

                   </asp:PlaceHolder>
               </div>






               <script>
                   _isen=<%=isen?"1":"0" %>;
               </script>

               <script>

                   var detail_cn = ["子件编号", "子件名称", "级别", "位置编号", "数量", "单位", "版本", "制造商编号", "制造商名称","用料说明","操作"];
                   var detail_en = ["Item Code", "Item Name", "Level", "Find NO.", "Quantity", "UOM", "Revision", "MPN", "Manufacturer", "Note","Action"];

               </script>











               <style>
                   .detail input[type=text] {
                       width: 90px;
                   }
               </style>



               <asp:UpdatePanel ID="UpdatePanel1" runat="server" ClientIDMode="AutoID">
        <ContentTemplate>

               <asp:GridView runat="server" ID="gv_items" Style="border-collapse: collapse"
                   GridLines="None" CssClass="table table-bordered table-hover detail"
                   AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="sds"
                    ClientIDMode="AutoID"
                   >

                   <Columns>
                       <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" Visible="false" />

                       <asp:BoundField DataField="ItemCode" HeaderText="子件编号" HeaderStyle-Width="90px" />
                       <asp:BoundField DataField="ItemName" HeaderText="子件名称" HeaderStyle-Width="160px" />
                       <asp:BoundField DataField="Levels" HeaderText="级别" HeaderStyle-Width="80px" />
                       <asp:BoundField DataField="findNumber" HeaderText="位置编号" HeaderStyle-Width="80px" />
                       <asp:BoundField DataField="quantity" HeaderText="数量" HeaderStyle-Width="80px" />
                       <asp:BoundField DataField="UOM" HeaderText="单位" HeaderStyle-Width="80px" />
                       <asp:BoundField DataField="revision" HeaderText="版本" HeaderStyle-Width="80px" />
                       <asp:BoundField DataField="MPN" HeaderText="制造商编号" HeaderStyle-Width="120px" />
                       <asp:BoundField DataField="Manufacturer" HeaderText="制造商名称" HeaderStyle-Width="150px" />

                     
                       <asp:BoundField DataField="Note" HeaderText="用料说明" HeaderStyle-Width="150px" />

                       <asp:CommandField ShowDeleteButton="true" ShowEditButton="true"
                           DeleteText="<span onclick=&quot;JavaScript:return confirm('确定删除吗？')&quot;>删除</span> "
                           EditText="编辑"
                           UpdateText="更新" CancelText="取消"
                           HeaderStyle-Width="100px" />
                   </Columns>



               </asp:GridView>



               <script>
                   var i = 0;
                   $(".detail th").each(
                       function () {
                           if (_isen == "1") {
                               $(this).html(detail_en[i]);
                           }
                           else {
                               $(this).html(detail_cn[i]);
                           }

                           i++;
                       }

                       );


               </script>




               <asp:SqlDataSource ID="sds" 
                   ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                   runat="server"
                   DeleteCommand="DELETE FROM [purchase_bom_items] WHERE [id] = @id"
                   SelectCommand="SELECT * FROM purchase_bom_items where bid=@bid ORDER BY [id]"
                   UpdateCommand="UPDATE purchase_bom_items SET itemcode=@itemcode,itemname=@itemname,levels=@levels,findnumber=@findnumber,quantity=@quantity, revision=@revision,uom=@uom,mpn=@mpn,manufacturer=@manufacturer,note=@note where id=@id ">

                   <SelectParameters>
                       <asp:QueryStringParameter DefaultValue="0" QueryStringField="id" Name="bid" />
                   </SelectParameters>
                   <DeleteParameters>
                       <asp:Parameter Name="id" Type="Int32" />
                   </DeleteParameters>





               </asp:SqlDataSource>



        </ContentTemplate>

    </asp:UpdatePanel>







           </div>
                           
                 























 


    








     <input type="hidden" name="hf_ids" id="hf_ids" />







        




</div>






        <script>

            function _preview(_cid)
            {
                window.open( document.getElementById(_cid).value);
            }

            function AddAttach(_cid,_path)
            {
                $("#" + _cid).val(_path);
            }
 

        </script>


        <script>

            function setCustomer(_customer)
            {
                $("#customercode").val(_customer.split('$')[0]);
                $("#customername").val(_customer.split('$')[1]);
               
            
            
            }

        </script>



    </div>




   

    <script>

        
        function disablescroll() {
            $("body").addClass("hdbody");
          
        }

        function enablescroll() {
            $("body").removeClass("hdbody");
        }


    </script>


</asp:Content>