<%@ page language="C#" autoeventwireup="true" inherits="SB_admin_N47_DeliveryNote_N47_DeliveryNote_Insert, App_Web_nvuefjsa" %>

<!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">
<head id="Head1" runat="server">
    <title>新增送货单</title>

    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/js/My97DatePicker/WdatePicker.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.min.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.easyui.min.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/locale/easyui-lang-zh_CN.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.load.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.json.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/easy_ui/jquery.easyui.validtor.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/js/PageDialog.js?v=1")%>"></script>

    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/easy_ui/themes/bootstrap/easyui.css?v=1")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/easy_ui/themes/icon.css?v=1")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/easy_ui/load.css?v=1")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/SB/control/css/main.css?v=1")%>" />
    
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/SB/control/js/My97DatePicker/WdatePicker.js?v=1")%>"></script>
<style>
.ipt{
border: 1px solid lightGrey;
background-color: white;
}

</style>
</head>
<body>
    <h3>
        新增送货单</h3>
    <form id="form1" runat="server">
        <table border="1" cellpadding="4" cellspacing="0" width="100%" bordercolor="#ccc" style="border-collapse:collapse">
            <tr>
                <td colspan="1">收货单位：</td>
                <td colspan="3">
                    <asp:TextBox ID="ddldn_customer" runat="server" MaxLength="100" Width="200px" class="easyui-combobox"  
                                data-options="  
                                url:'../N47_Customer/N47_Customer_ComboData.aspx',
                                valueField: 'id',  
                                textField: 'c_name',
                                onSelect:customerSelect
                       "></asp:TextBox>
                    <script language="javascript"  type="text/javascript">
                    function customerSelect(row){
                        $("#txtdn_address").val(row.c_address);
                    }
                    </script>
                     <a href="#" onclick="selectProject()">选择发货项</a>
                        
                </td>
                <td colspan="1">送货单号：</td>
                <td colspan="3">
                    <asp:TextBox ID="txtdn_number" runat="server" MaxLength="50" Width="60%"></asp:TextBox>
                    <asp:RequiredFieldValidator  ID="rfvdn_number" runat="server" ErrorMessage="必填" ControlToValidate="txtdn_number"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td colspan="1">地址：</td>
                <td colspan="3">
                    <asp:TextBox ID="txtdn_address" runat="server" MaxLength="100" Width="300px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvdn_address" runat="server" ErrorMessage="必填" ControlToValidate="txtdn_address"></asp:RequiredFieldValidator>
                </td>
                <td colspan="1" style="width: 81px; height: 24px">日期：</td>
                <td colspan="3">
                    <asp:TextBox ID="txtdn_date" runat="server" Width="60%" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvdn_date" runat="server" ErrorMessage="必填" ControlToValidate="txtdn_date"></asp:RequiredFieldValidator>
                 </td>
            </tr>
            <tr>
                <td colspan="8" style="height: 127px" valign="top">
                 <table border="1" cellpadding="3" cellspacing="0" width="100%" style="border-collapse:collapse" bordercolor="#ccc">
                 <thead> 
                 <tr style="background-color:#ccc">
                     <td align="center">
                     <a href="#" onclick="selectProject()">新增</a>
                         </td>
                 <td align="center">项目编号</td><td align="center">名称</td><td align="center">名称及规格</td><td align="center">单位</td><td align="center">数量</td><td align="center">单价</td><td align="center">金额</td>
                  </tr>
                  </thead>
                 <tbody id="bodyContent"> 
                
                     <tr align="center" id="defaultTr" style=" display:none;" >
                       <td>
                       <a href="#" onclick='$(this).parent().parent().remove()'>X</a>
                       </td>
                         <td>
                             <input type="text" role='hh' style="width: 83px" class="ipt" readonly="readonly"  />
                         </td>
                          <td>
                             <input type="text" role='name'  class="ipt" readonly="readonly"  />
                         </td>
                         <td>
                             <input type="text" role='mcgg' class="ipt" /></td> 
                         <td>
                             <input  style="width: 89px" role='dw' type="text"  class="ipt" />
                         </td>
                         <td>
                             <input style="width: 95px" role='sl' type="text" class="ipt" onfocusout='sump(this)'  />
                         </td>
                         <td>
                             <input  style="width: 89px" role='dj' type="text" class="ipt"  onfocusout='sump(this)' />
                         </td>
                         <td>
                             <input  style="width: 89px" role='je' type="text"  readonly="readonly" class="ipt" />
                         </td>
                     </tr>
                 </tbody>
                   </table>
                </td>
            </tr>
          
            <tr>
                <td colspan="1">
                    备注：</td>
                <td colspan="3">
                    <asp:TextBox ID="txtdn_note" runat="server" MaxLength="50" Width="60%"></asp:TextBox></td>
                <td colspan="1">
                    送货单位：</td>
                <td colspan="3">
                    <asp:TextBox ID="txtdn_delivery" runat="server" MaxLength="50" Width="200"   Text="AAA"
                    class="easyui-combobox" data-options="
		            valueField: 'label',
		            textField: 'value',
		            data: [{
			            label: 'BBB',
			            value: 'BBB'
		            },{
			            label: 'CCC',
			            value: 'CCC'
		            }]" 
                    ></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvdn_delivery" runat="server" ErrorMessage="必填"
                        ControlToValidate="txtdn_delivery"></asp:RequiredFieldValidator></td>
            </tr>
            <tr>
                <td colspan="1">
                </td>
                <td colspan="3">
                    <asp:Button ID="btnSubmit" runat="server" Text="保存" Width="80px" OnClick="btnSubmit_Click" OnClientClick='return beforedSubmit()' />
                    <asp:Button ID="btnClose" runat="server" Text="保存并关闭" OnClick="btnClose_Click" OnClientClick='return beforedSubmit()'/>
                    <asp:HiddenField ID="hfoption" runat="server" />
                </td>
                <td colspan="1">
                </td>
                <td colspan="3">
                </td>
            </tr>
        </table>
    </form>
    
    <script language="javascript" type="text/javascript">
    function selectProject(){
        var customer = $("#ddldn_customer").combobox("getValue");
        
        if(customer==''){
           alert('请选择收货单位');
        }else{
          ShowDialog("select","../N47_Project/N47_Project_Select.aspx?customer="+customer,500,300,200,200);
        }
        
    }
    
    function addProject(id,index,p_spe,p_unit,p_quantity,p_unitPrice,name){
    
        var newRow = $("<tr align='center' >"+$("#defaultTr").html()+"</tr>");
        
        newRow.find("input[role='hh']").val(index);
        newRow.find("input[role='mcgg']").val(p_spe);
        newRow.find("input[role='name']").val(name);

        newRow.find("input[role='dw']").val(p_unit);
        newRow.find("input[role='sl']").val(p_quantity); 
        newRow.find("input[role='dj']").val(p_unitPrice);
        newRow.find("input[role='je']").val(toDecimal(p_quantity*p_unitPrice));
        newRow.attr("id",id);
        $("#bodyContent").append(newRow);
  
        
    }
    
    function sump(obj){
        var newRow= $(obj).parent().parent();
        var sl =newRow.find("input[role='sl']").val();
        sl = $.trim(sl)=="" ? 0 : parseFloat(sl);
        var dj =  newRow.find("input[role='dj']").val();
        dj = $.trim(dj)=="" ? 0 : parseFloat(dj);
        newRow.find("input[role='je']").val(toDecimal(sl*dj));
    }
    function toDecimal(x) {    
            var f = parseFloat(x);    
            if (isNaN(f)) {    
                return;    
            }    
            f = Math.round(x*100)/100;    
            return f;    
    }
    function beforedSubmit(){
         if (!Page_ClientValidate()) {
             return false; 
         }
        var list = new Array();
        var items = $("#bodyContent").children();
        for(var i=1;i<items.size();i++){
            var tr = items.eq(i);
            
            var id = tr.attr("id");
            var index = $.trim(tr.find("input[role='hh']").val());
            var spe = $.trim(tr.find("input[role='mcgg']").val());
            var unit = $.trim(tr.find("input[role='dw']").val());
            var number = $.trim(tr.find("input[role='sl']").val());
            var price = $.trim(tr.find("input[role='dj']").val());
            if(index!=''&&spe!=''&&unit!=''&&number!=''&&price!=''){
    
                 if(isNaN(number)){alert("第"+i+'行数量请输入整数！');return false;}
                 if(isNaN(price)){alert("第"+i+'行单价无效格式！');return false;}
                 list.push(new Item(id,index,spe,unit,number,price));
            }else{
                 
                alert("发货内容需完整填写！");
                return false;
            }
           
        }
         $("#hfoption").val($.toJSON(list));
        
         return true;
    }
    Item = function(_id,_index,_spe,_unit,_number,_price){
        this.id = _id;
        this.index = _index;
        this.spe = _spe;
        this.unit = _unit;
        this.number = _number;
        this.price = _price;
    }
    </script>
</body>
</html>
