<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sms_telbookcontact_editlist.aspx.cs" Inherits="VA.Modules.JDingMember.sms.sms_telbookcontact_editlist" %>

<%@ Import Namespace="System.Data"%>

<!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>
<title>电话本联系人管理</title>    
    <!--#include virtual="/include/css/editlist.aspx"-->
    <!--#include virtual="/include/js/editlist.aspx"--> 
    <script type="text/javascript">


        //添加；
        function add(){                        
            openFrameWindow("添加联系人", 535, 255, "sms_telbookcontact_edit.aspx");
        }     

        //单条修改；
        function smodify(keyValue) {
            var ids = keyValue;
            openFrameWindow("修改联系人", 535, 255, "sms_telbookcontact_edit.aspx?rid=" + ids);
            event.stopPropagation();  //阻止事件冒泡，避免行被选中；
        }

        //删除；
        function del() {
            batchllyActWrapper("Del", "确定要删除选定项吗？", "");
        }

        //单条删除；
        function sdel(keyValue) {
            singleActWrapper("Del", keyValue, "确定要删除该项吗？", "");
        }

        //分类管理；
        function categoryManage() {
            openFrameWindow("联系人分类管理", 735, 350, "sms_telbookcontactcategory_editlist.aspx");
        }

        //取消
        function cancel() {
            window.parent.closeFrameWindow();
        }

        //确定
        function ok() {
            window.parent.finishTakeTelBookContacts();
        }

        //======================
       
        var keyIDArray = new Array();

        //选择全部记录
        function selectAllRecords() {
            var requestType = "GET";
            var url = pageName + "?act=get";  //pageName在BasePage中注册到的客户端；
            var dataType = "html";
            var data = $("form").eq(0).serialize();
            var successFN = function (data, textStatus) {                
                if (data.indexOf("01|") != -1) {
                    //do nothing
                }
                else {
                    keyIDArray = data.split('|');
                    selectRows();
                }
            };
            ajaxRequest(requestType,
                url,
                dataType,
                data,
                successFN,
                errorFN
                );
        }

        //根据keyIDArray数组的值来选中行；
        function selectRows() {
            var $dataTable = $("#tablebody");
            var $dataRows = $dataTable.find("tr");
            $dataRows.each(function () {
                var checkboxObj = $(this).find(":checkbox")[0];
                var keyID = this.cells[3].innerHTML; //取手机号
                if (keyIDArray.indexOf(keyID) != -1) {
                    smartListTable_selectTR(true, $(this));
                    checkboxObj.checked = true;
                }
            });
        }

        //选择当页记录
        function selectCurrentPageRecords() {
            var tableID = "tb1_header";
            smartListTable_selectAll(tableID, true);
        }

        //列表页数据加载完毕后会自动调用该函数；
        function afterDataListLoaded() {
            selectRows();
        }

        function JTongSmartListTable_afterSelect(trObj) {
            //var keyID = $(trObj.cells[1]).find("input:hidden").val();
            var keyID = trObj.cells[3].innerHTML; //取手机号
            addRow(keyID);
        }

        function JTongSmartListTable_afterCancelSelect(trObj) {
            //var keyID = $(trObj.cells[1]).find("input:hidden").val();
            var keyID = trObj.cells[3].innerHTML; //取手机号
            removeRow(keyID);
        }

        function addRow(keyID) {
            if (keyID == "手机号") {
                return;
            }
            if (keyIDArray.indexOf(keyID) == -1) {
                keyIDArray.push(keyID);
            }
        }

        function removeRow(keyID) {
            var index = keyIDArray.indexOf(keyID);
            if (index != -1) {
                keyIDArray.splice(index, 1);
            }
        }

        function ok() {

            var keyIDString = keyIDArray.join("|");

            var takeOption = $('input:radio[name=rbnTakeOption]:checked').val();            
            window.parent.finishTakeTelBookContacts(keyIDString, takeOption);
        }

        //======================

        $(function () {
            initListPage();
        });
    </script>

</head>
<body>
<!--说明：该页面是以 employee_editlist_nofresh_5.aspx 为原型封装的结果-->
<form id="Form1" method="post" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

<div id="pageWrapper" class="pageWrapper">   
    
    <div id="toolBar">                      
         <a href="javascript:selectAllRecords()" class="jtongui-toolbarbutton" icon="icon-add">选择全部记录</a>
        <a href="javascript:selectCurrentPageRecords()" class="jtongui-toolbarbutton" icon="icon-add">选择本页记录</a>    
        <a href="javascript:add()" class="jtongui-toolbarbutton" icon="icon-add">添加</a>
        <a href="javascript:del()" class="jtongui-toolbarbutton" icon="icon-delete">删除</a>                       
        <a href="javascript:categoryManage()" class="jtongui-toolbarbutton" icon="icon-disable">分类管理</a>                        
        <asp:LinkButton ID="lbnExportToExcel" runat="server" CssClass="jtongui-toolbarbutton" icon="icon-export" OnClick="lbnExportToExcel_Click">导出</asp:LinkButton>                
        <a href="javascript:refresh()" class="jtongui-toolbarbutton" icon="icon-reload">刷新</a>
    </div><!--toolBar.END--> 
          
    <div id="searchBar">
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>

        <asp:DropDownList ID="ddlCategory" runat="server" 
             AutoPostBack="true"
             OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged">           
        </asp:DropDownList>
            
        <asp:DropDownList ID="ddlSearchField" runat="server" EnableViewState="false">
        <asp:ListItem Value="">检索字段</asp:ListItem>
        <asp:ListItem Value="1">姓名</asp:ListItem>
        <asp:ListItem Value="2">手机号</asp:ListItem>        
        </asp:DropDownList>                                

        <asp:TextBox ID="txtKeyWords" runat="server"
            CssClass="input keywords"
            Width="100px" />     
      
        <asp:DropDownList ID="ddlOrderBy" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlOrderBy_SelectedIndexChanged">
        <asp:ListItem Value="">排序规则</asp:ListItem>
        <asp:ListItem Value="RID|ASC">添加顺序-正序</asp:ListItem>
        <asp:ListItem Value="RID|DESC">添加顺序-倒序</asp:ListItem>
        <asp:ListItem Value="Contact_Name|ASC">联系人姓名-正序</asp:ListItem>
        <asp:ListItem Value="Contact_Name|DESC">联系人姓名-倒序</asp:ListItem>
        <asp:ListItem Value="MobileNo|ASC">手机号-正序</asp:ListItem>
        <asp:ListItem Value="MobileNo|DESC">手机号-倒序</asp:ListItem>
        </asp:DropDownList>             
         
        <asp:Button ID="btnSearch" runat="server" 
             CssClass="simpleBtn"
             Text="查询" 
             Onclick="btnSearch_Click" />
        
        </ContentTemplate>
        </asp:UpdatePanel>

    </div><!--searchBar.END-->    

    <div id="dataBar">

    <!--MainList.Start-->    
    <div class="jtongui-smartlisttable" id="jtongui-smartlisttable">

    <table cellpadding="3" cellspacing="0" class="tableheader" id="tb1_header" >
    <thead>
    <tr>
        <td style="width:30px;text-align:center;"><input type="checkbox" id="ckb_selectAll"/></td>
        <td style="width:30px;text-align:center;">No.</td>        
        <td style="width:100px;text-align:center;">姓名</td>        
        <td style="width:100px;text-align:center;">手机号</td>        
	    <td style="width:200px;text-align:center;">备注</td>        
        <td style="width:30px;text-align:center;">修改</td>
        <td style="width:30px;text-align:center;">删除</td>
        <td></td>
    </tr>    
    </thead>
    </table>

    <div id="dataBody">
    <asp:Repeater ID="myRepeater" Runat="server" EnableViewState="False"  >
    <HeaderTemplate>
    <div class="bodyContainer">
    <% = base.ShowNoRecordInfo() %>    
    <table  id="tablebody" cellpadding="3" cellspacing="0" class="tablebody" tbHeader="tb1_header">
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
        <td style="text-align:center;"><input type="checkbox" name="ckb_dataItem" value="<%# Eval("RID")%>" /></td>
        <td align="center"><%# (base.currPage - 1)*base.PageSize + Container.ItemIndex + 1%>
            <input type="hidden" value="<%# Eval("RID")%>" />
        </td>
        <td align="center"><%# Eval("Contact_Name")%></td>
        <td align="center"><%# Eval("MobileNo")%></td>                
        <td align="center"><%# Eval("Remark")%></td>        
        <td align="center">
            <a href="#" onclick="javascript:smodify('<%# Eval("RID")%>');"><img src="/app_themes/icons/edit.png" alt="修改"/>  </a>
        </td>              	       	       
        <td align="center">
            <a href="#" onclick="javascript:sdel('<%# Eval("RID")%>');"><img src="/app_themes/icons/delete.png" alt="删除"/>  </a>
        </td>      
        <td></td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </div><!--bodyContainer.END-->        

    <div id="divPagerInfo" style="display:none">
        <%=base.pageInfo%>
    </div>

    <input type="hidden" id="hidden_pageCnt" value="<% = base.PageCnt%>" />
    <input type="hidden" id="hidden_rdCnt" value="<% = base.RdCnt%>" />
    <input type="hidden" name="chkNum" value="<%=chkNum%>" />

    </FooterTemplate>
    </asp:Repeater>    
    </div><!--dataBody.END-->

    </div><!--jtongui-smartlisttable.END-->        
    <!--MainList.End-->  

    </div><!--dataBar.END-->

    <div id="pagerBar">
       ……
    </div><!--pageNavBar.END-->
    
    <asp:HiddenField runat="server" ID="hfCurrPage" EnableViewState="true" />

    <div id="bottomToolBar">             

        <asp:RadioButtonList ID="rbnTakeOption" runat="server"
             RepeatDirection="Horizontal"
             RepeatLayout="Flow">
            <asp:ListItem Value="1">覆盖</asp:ListItem>
            <asp:ListItem Value="2" Selected="True">追加</asp:ListItem>
        </asp:RadioButtonList>

        <input type="button" id="btnOk" class="btn" style="width:100px" onclick="ok()" value="确定" />
        <input type="button" id="btnCancel" class="btn" style="width:100px" onclick="cancel()" value="取消" />
    </div><!--toolBar.END--> 
    
</div>

</form>
</body>
</html> 