<%@ page language="C#" autoeventwireup="true" inherits="WebAdmin_Unitlist, LebiMall" %>
<!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 runat="server">
    <title>产品单位设置</title>
    <link href="css/css.css" rel="stylesheet" type="text/css" />
    <link href="css/tipswindown.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" language="javascript" src="js/topHead.js"></script>
    <script type="text/javascript" src="js/checked.js"></script>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/tipswindown.js" type="text/javascript"></script>
    <script type="text/javascript">
        var $=jQuery;
        var trc='<%=count %>';
        var m_objTable; 
        function addTRow(){
            var table=document.getElementById("list");
            var vt=table.rows.length;
            var rows=table.insertRow(vt);
            if(trc%2==0){
                rows.className = "ctr2";
                rows.onmouseover=function(){chColor(this,"#ebebeb");};
                rows.onmouseout=function(){chColor(this,"#fafafa");};
            }else{
                rows.className = "ctr";
                rows.onmouseover=function(){chColor(this,"#ebebeb");};
                rows.onmouseout=function(){chColor(this,"#ffffff");};
            }
            //添加checkbox
            var cell1 = rows.insertCell(0);
            cell1.className = "row";
            cell1.innerHTML+="&nbsp;<input type='hidden' id='hidden_id"+trc+"' name='hidden_id"+trc+"' value='0'/>";
            //名称
            var cell2 = rows.insertCell(1);
            cell2.className = "row";
            cell2.innerHTML = "<input type='text' id='txt_name"+trc+"' name='txt_name"+trc+"' value='' class='input' />";
            //操作
            var cell3 = rows.insertCell(2);
            cell3.className = "row";
            cell3.innerHTML = " <a href='javascript:void(0)' onclick='delRow(list);' >删除</a> ";
            vt++;
            trc++;
        }
        function delRow(table)   
        {   if( typeof(table) != "undefined" )        
                setTable(table); 
            try   
            {   
                var Elm=event.srcElement;
                while(Elm  &&  Elm.tagName  !=  "TR")   
                {   
                    Elm  =  Elm.parentElement;   
                }
                var intThisIndex = Elm.rowIndex; 
                Elm.parentElement.deleteRow(intThisIndex);  
            }   
            catch(ex)   
            {   
                alert("delRow() Err  5001:\r\n"  +  ex.description);   
                
            }
        }
        function setTable(table)           
        { 
            if(typeof(table) == "string") 
                this.m_objTable = getObjTableByID(table); 
            else if(typeof(table) == "object") 
                this.m_objTable = table; 
        }
        function update(id_,i){
            var uname=document.getElementById("txt_name"+i).value;
            window.location.href="Unitedit.aspx?id="+id_+"&u_name="+escape(uname)+"&type=update";
        }
        function del(id){
            if (confirm("确认要删除？")) {
                window.location.href="Unitedit.aspx?id="+id+"&type=delete";
            }
        }
        //批量删除
        function dels(id){
            var form =document.forms[0];
            var strid="";
            if (confirm("确认要删除？")) {
                for(i=0;i<form.elements.length;i++)
                {
                    if(form.elements[i].type=="checkbox")
                    {
                        if(form.elements[i].checked==true){
                            if(form.elements[i].value!="")
                            strid+=form.elements[i].value+",";
                        }
                    }
                }
                if(strid!="")
                window.location.href="Unitedit.aspx?ustrid="+strid+"&type=dels";
            }
        }
        function restore(){
            if (confirm("是否要恢复原始数据？")){
                window.location.href="Unitedit.aspx?type=restore";
            }
        }
        //保存
        function updates(){
            var form =document.forms[0];
            var flag=false;
            for(i=0;i<form.elements.length;i++)
            {
                if(form.elements[i].type=="text")
                {
                    if(form.elements[i].value==""){
                        document.getElementById("msg").innerHTML="<span class='msg_submit'>单位名称不能为空</span>";
                        flag=false;
                        break;
                    }else{
                        flag=true;
                    }
                }
            }
            if(flag){
                document.getElementById("hidden_count").value=trc;
                document.getElementById("form1").submit();
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <script>header(2,3,"images/");</script>
        <div class="tab-mainbody3">
            <div class="tab-mainbody4">
                <div class="functionHandleArea clearfix">
                        <input type="image" title=" 保存 " onclick="updates();return false;" src="images/bt_app.gif" align="absmiddle" />
                        <input type="image" name="Submit" title=" 删除 " onClick="dels();return false;" src="images/bt_delete.gif" align="absmiddle" />
                        <input type="image" title=" 添加 " onclick="addTRow();return false;" src="images/bt_add.gif" align="absmiddle" />
                        <span id="msg"></span>
            </div>
                <div id="datalist">
                <table cellspacing="0" width="100%" cellpadding="0" id="list">
                    <tr>
                        <th style="width: 5%; cursor: pointer;" title="全选" onclick="AllChecked()">
                            选择</th>
                        <th style="width: 85%">
                            名称</th>
                        <th style="width: 10%">
                            操作
                        </th>
                    </tr>
                    <%for (int i = 0; i < ds.Tables[0].Rows.Count; i++){%>
                    <tr class="row">
                        <td class="row">
                            <input type="checkbox" value="<%=ds.Tables[0].Rows[i]["id"] %>" />
                            <input type="hidden" id="hidden_id<%=i %>" name="hidden_id<%=i %>" value="<%=ds.Tables[0].Rows[i]["id"] %>" />
                        </td>
                        <td class="row">
                            <input type="text" id="txt_name<%=i %>" name="txt_name<%=i %>" value="<%=ds.Tables[0].Rows[i]["uname"] %>"
                                class="input" />
                        </td>
                        <td class="row">
                             <a href="javascript:del(<%=ds.Tables[0].Rows[i]["id"] %>)">删除</a>&nbsp;|&nbsp;<a href="javascript:update(<%=ds.Tables[0].Rows[i]["id"] %>,<%=i %>)">
                                修改</a>
                        </td>
                    </tr>
                    <%} %>
                </table>
                <script type="text/javascript">tdshowm("list");</script>
                <script type="text/javascript">
                    var fc='<%=returnValue %>';
                    var i = 2;
                    if(fc=="true"){
                        tipsWindown("提示","text:操作成功！","250","60","true","2000","true","");
                        
                    }
                    if(fc=="false"){
                        tipsWindown("提示","text:操作失败！","250","60","true","2000","true","");
                    }
                </script>
                <input type=hidden id="hidden_count" runat=server />
            </div>
        </div>
        </div>
    </form>
</body>
</html>
