<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation = "false" CodeBehind="Computersband.aspx.cs" 
Inherits="SmartLogonServer.Computersband" %>

<!DOCTYPE html>


<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <!--必须的css引用-->
    <link href="Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="Content/bootstrap-table/bootstrap-table.min.css"  rel="stylesheet" />
       <link href="Content/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet" />
<link href="Content/bootstrap-table/extensions/fixed-column/bootstrap-table-fixed-columns.css"  rel="stylesheet" />
    <link href="Content/toastr/toastr.min.css"  rel="stylesheet" />

</head>
<body>
    <div class="panel-body" style="padding-bottom:0px;">
                <div id="toolbar" class="btn-group">
            <button id="btn_add" type="button" class="btn btn-success">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span><%=GetString("B0021") %>
            </button>

        </div>  

         <table id="tb_computerband"></table>
    </div>

    <!--新增或者编辑的弹出框-->
    <div class="modal fade" id="myModalselectmainpc" tabindex="-1"  role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel"><%=GetString("D0105") %></h4>
                </div>
                <div class="modal-body">

                    
             <div class="panel panel-default">
            <div class="panel-heading"><%=GetString("D0006") %></div>
            <div class="panel-body"> 
                <form id="formSearchpc" class="form-horizontal">
                    <div class="form-group">
                        <div class ="row">
                        <label class="control-label col-xs-3" for="txt_search_text"><%=GetString("D0066") %></label>
                        <div class="col-xs-4">
                            <input type="text" class="form-control" id="pccode_search"/>
                        </div>
                        
   
                        <div class="col-xs-4" style="text-align:right;">
                            <button type="button" id="btnpc_clear"  class="btn"><%=GetString("B0030") %></button>
                            <button type="button" id="btnpcquery" class="btn btn-primary"><%=GetString("B0031") %></button>
                        </div>
                            </div>
                    </div>
                </form>
            </div>  
                 </div>
        </div>
                    
                    
                    <table id="tb_selectmainpc" ></table>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span><%=GetString("B0025") %></button>
                    <button type="button" id="sava-mainpc-btn" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span><%=GetString("B0026") %></button>
                </div>
                
            </div>
        </div>
    </div>


    <div class="modal fade" id="myModalselectbandpc" tabindex="-1"  role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalbandpcLabel"><%=GetString("D0106") %></h4>
                </div>
                <div class="modal-body">
                        <div class="row" style="padding:2px;">
                        <label class="control-label  col-md-2"><%=GetString("D0107") %></label>
                        <div class="col-md-4">
                            <input type="text" id="edtComputerid" name="edtComputerid" readonly="true"  />
                        </div>

                    </div>
                    
             <div class="panel panel-default">
            <div class="panel-heading"><%=GetString("D0006") %></div>
            <div class="panel-body"> 
                <form id="formSearchcard" class="form-horizontal">
                    <div class="form-group">
                        <div class ="row">
                        <label class="control-label col-xs-3" for="txt_search_text"><%=GetString("D0066") %></label>
                        <div class="col-xs-4">
                            <input type="text" class="form-control" id="txt_search_text"/>
                        </div>
                        
   
                        <div class="col-xs-4" style="text-align:right;">
                            <button type="button" id="btncard_clear"  class="btn"><%=GetString("B0030") %></button>
                            <button type="button" id="btncard_query" class="btn btn-primary"><%=GetString("B0031") %></button>
                        </div>
                            </div>
                    </div>
                </form>
            </div> 
                 </div> 
        </div>
                    <table id="tb_selectbandpc" ></table>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span><%=GetString("B0025") %></button>
                    <button type="button" id="sava-bandpc-btn" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span><%=GetString("B0026") %></button>
                </div>
                
            </div>
        </div>
    </div>

   
        <!--必须的js文件-->
        <script src="Content/jquery-1.9.1.min.js"></script>
        <script src="Content/bootstrap/js/bootstrap.min.js"></script>
        <script src="Content/bootstrap3-editable/js/bootstrap-editable.js"></script>
        <script src="Content/bootstrap-table/bootstrap-table.min.js"></script>
        <script src="Content/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
        <script src="Content/bootstrap-table/extensions/editable/bootstrap-table-editable.min.js"></script>
            <script src="Content/toastr/toastr.min.js"></script>
        <script src="Content/sweetalert/sweetalert.min.js"></script>
            <script src="Content/moment.min.js"></script>


        <script type="text/javascript">
            //页面加载完成之后


            $(function () {
          
               
                //表格的初始化
                $('#tb_computerband').bootstrapTable({
                    url: "computerband.ashx",                         //直接从本地数据初始化表格
                    method: 'get',                      //请求方式（*）
                    //datatype: "json",
                    //contentType: "application/x-www-form-urlencoded",
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    idField: 'ComputerID',
                    uniqueId: 'ComputerID',
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: function (params) {
                        var pages = {
                            limit: params.pageSize, // 每页显示数量
                            offset: params.pageNumber, // SQL语句起始索引

                        }

                        return JSON.stringify(pages);
                    },                                  //传递参数（*）
                    queryParamsType: "",
                    sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                      //初始化加载第一页，默认第一页
                    pageSize: 25,                       //每页的记录行数（*）
                    pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                    search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: true,                  //是否显示所有的列

                    showRefresh: true,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    height: 800,
                    selectItemName: 'parentItem',
                    fixedColumns: true,
                    fixedNumber: 6,
                    showToggle: true,          //是否显示详细视图和列表视图的切换按钮
                    cardView: false,          //是否显示详细视图
                    showExport: false, //是否显示导出按钮
                    exportDataType: "all",
                    exportTypes: ['excel'], //导出文件类型
                    detailView: true,
                    //注册加载子表的事件。注意下这里的三个参数！
                    onExpandRow: function (index, row, $detail) {
                        InitSubTable(index, row, $detail);
                    },
                    checkboxHeader: false,
                    columns: [{
                        checkbox: false,
                        width: 10
                    }, {
                        field: 'ComputerID',
                        title: <%=GetQuoteString("D0107") %>,
                        width: 100

                    }, {
                        field: 'ComputerName',
                        title: <%=GetQuoteString("D0017") %>,
                        width: 200

                    }, {
                        title: <%=GetQuoteString("B0027") %>,
                        width: 200,
                        formatter: function (value, row, index) {//这里的三个参数：value表示当前行当前列的值；row表示当前行的数据；index表示当前行的索引（从0开始）。
                            var html = '<button type="button" onclick="addpc(\'' + row.ComputerID + '\')" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria- hidden="true" ></span >'+ <%=GetQuoteString("B0048") %> + '</button >'
                                    + '<button type="button" onclick="deletepc(\'' + row.ComputerID + '\')" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria- hidden="true" ></span >'+ <%=GetQuoteString("B0049") %> + '</button >'
                            return html;
                        }
                    }],
                    onEditableSave: function (field, row, oldValue, $el) {
                       

                    }
                });



                var InitSubTable = function (index, row, $detail) {
                    var parentid = row.ComputerID;
                    var cur_table = $detail.html('<table id="cardtable' + row.ComputerID + '"></table>').find('table');
                    //子表的初始化和父表完全相同
                    $(cur_table).bootstrapTable({
                        url: 'computerbandsub.ashx',
                        //data: childData,
                        method: 'get',
                        queryParams: { mainpccode: parentid },
                        ajaxOptions: { mainpccode: parentid },
                        clickToSelect: true,
                        uniqueId: "mainpccode",
                        pageSize: 10,
                        pageList: [10, 25],
                        selectItemName: 'childItem' + index,
                        checkboxHeader: false,
                        columns: [{
                            checkbox: false,
                            width: 10
                        },{
                            field: 'mainpccode',
                            title: <%=GetQuoteString("D0108") %>
                        }, {
                            field: 'ComputerName',
                            title: <%=GetQuoteString("D0017") %>

                        }, {
                            title: <%=GetQuoteString("B0027") %>,
                            width: 200,
                            formatter: function (value, row, index) {//这里的三个参数：value表示当前行当前列的值；row表示当前行的数据；index表示当前行的索引（从0开始）。
                                var html = '<button type="button" onclick="removepc(\'' + row.mainpccode + '\',\''+ parentid+ '\')"' + 'class="btn btn-outline-secondary"><span class="glyphicon glyphicon-minus" aria- hidden="true" ></span >'+ <%=GetQuoteString("B0044") %> + '</button >';

                                return html;
                            }
          
                        }],
                        onEditableSave: function (field, row, oldValue, $el) {
 
                        },
                        //无线循环取子表，直到子表里面没有记录
                        onExpandRow: function (index, row, $Subdetail) {
                            //oInit.InitSubTable(index, row, $Subdetail);
                        }
                    });
                

                };
            });



            //编辑事件
            var addpc = function (id) {
                //根据当前行的id获取当前的行数据

                // var row = $("#tb_computer").bootstrapTable('getRowByUniqueId', id);
                //弹出模态框   edtAccessmode

                $("#myModalselectbandpc").modal();
                //给弹出框里面的各个文本框赋值
                $("#myModalselectbandpc input[name='edtComputerid']").val(id);
      
      
                //表格的初始化
                $('#tb_selectbandpc').bootstrapTable({
                    url: "computerbandsubselect.ashx",                         //直接从本地数据初始化表格
                    method: 'get',                      //请求方式（*）
                    //datatype: "json",
                    //contentType: "application/x-www-form-urlencoded",
                    //toolbar: '#toolbar',                //工具按钮用哪个容器
                    idField: 'ComputerID',
                    uniqueId: 'ComputerID',
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: function (params) {
                        var pages = {
                            limit: params.pageSize, // 每页显示数量
                            offset: params.pageNumber, // SQL语句起始索引
                            computerid: $("#edtComputerid").val(),
                            keystr: $("#txt_search_text").val()
                        }

                        return JSON.stringify(pages);
                    },
                    queryParamsType: "",                                 //传递参数（*）
                    sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                      //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 25],        //可供选择的每页的行数（*）
                    search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: false,                  //是否显示所有的列

                    showRefresh: false,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    //height: 600,
                    selectItemName: 'parentItem',
                    fixedColumns: true,
                    fixedNumber: 6,
                    showToggle: false,          //是否显示详细视图和列表视图的切换按钮
                    cardView: false,          //是否显示详细视图
                    showExport: false, //是否显示导出按钮
  
                    //注册加载子表的事件。注意下这里的三个参数！
                    onExpandRow: function (index, row, $detail) {
                        //InitSubTable(index, row, $detail);
                    },
                    columns: [{
                        checkbox: true
                    }, {
                        field: 'ComputerID',
                        title: <%=GetQuoteString("D0108") %>,
                        width: 100

                    }, {
                        field: 'ComputerName',
                        title: <%=GetQuoteString("D0017") %>,
                        width: 200

                    }]
        
                    
                });


            }

                //新增事件
            $("#btn_add").on('click', function () {
                $('#myModalselectmainpc').bootstrapTable("resetView");
                //弹出模态框
               
                $("#myModalselectmainpc").modal();
                //给弹出框里面的各个文本框赋值
                $("#myModalselectmainpc input").val("");

                $('#tb_selectmainpc').bootstrapTable({
                    url: "computerbandmainselect.ashx",                         //直接从本地数据初始化表格
                    method: 'get',                      //请求方式（*）
                    //datatype: "json",
                    //contentType: "application/x-www-form-urlencoded",
                    //toolbar: '#toolbar',                //工具按钮用哪个容器
                    idField: 'ComputerID',
                    uniqueId: 'ComputerID',
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: function (params) {
                        var pages = {
                            limit: params.pageSize, // 每页显示数量
                            offset: params.pageNumber, // SQL语句起始索引
                            keystr: $("#myModalselectmainpc input[name='pccode_search']").val()
                        }

                        return JSON.stringify(pages);
                    },
                    queryParamsType: "",                                 //传递参数（*）
                    sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                      //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 25],        //可供选择的每页的行数（*）
                    search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: false,                  //是否显示所有的列
                    singleSelect:true,
                    showRefresh: false,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    //height: 600,
                    selectItemName: 'parentItem',
                    fixedColumns: true,
                    fixedNumber: 6,
                    showToggle: false,          //是否显示详细视图和列表视图的切换按钮
                    cardView: false,          //是否显示详细视图
                    showExport: false, //是否显示导出按钮
  
                    //注册加载子表的事件。注意下这里的三个参数！
                    onExpandRow: function (index, row, $detail) {
                        //InitSubTable(index, row, $detail);
                    },
                    columns: [{
                        checkbox: true
                    }, {
                        field: 'ComputerID',
                        title: <%=GetQuoteString("D0016") %>,
                        width: 100

                    }, {
                        field: 'ComputerName',
                        title: <%=GetQuoteString("D0017") %>,
                        width: 200

                    }]
        
                    
                });
            });

            //删除事件
            var deletepc= function (computerid) {
    
                swal({
                    title: <%=GetQuoteString("D0109") %>,
                    text: <%=GetQuoteString("D0110") %> + computerid,
                    icon: "warning",
                    // buttons: true,
                    dangerMode: true,
                    buttons:{
                        cancel: <%=GetQuoteString("B0029") %>,
                        confirm: {
                            text: <%=GetQuoteString("B0028") %>,
                            value: 'confirm'
                        }
                    }
                })
    .then((value) => {
        if (value==='confirm') {

                    $.ajax({
                    type: "post",
                url: "computerbandedit.ashx",
                data: {
                    'mode': 'deletemain',
                    'computerid': computerid

                },
                dataType: 'JSON',
                success: function (data, status) {
                    if (status == "success") {
                        if (data.result == true) {
                                    

                            $('#tb_computerband').bootstrapTable("refresh", {
                                silent: true //静态刷新
                            });
                            toastr.success(<%=GetQuoteString("C0005") %>);
                        }
                        else {
                            toastr.error(<%=GetQuoteString("C0006") %>);
                        }
                    }
                },
                error: function () {
                    toastr.error(<%=GetQuoteString("C0006") %>);
                },
                complete: function () {

                }

            });
            }
            });//then
            }
  

 
            //删除事件
            var removepc= function (computerid, pid) {
    
                swal({
                    title: <%=GetQuoteString("D0111") %>,
                    text: <%=GetQuoteString("D0112") %> + computerid,
                    icon: "warning",
                    // buttons: true,
                    dangerMode: true,
                    buttons:{
                        cancel: <%=GetQuoteString("B0029") %>,
                        confirm: {
                            text: <%=GetQuoteString("B0028") %>,
                            value: 'confirm'
                        }
                    }
                })
    .then((value) => {
        if (value==='confirm') {

                    $.ajax({
                    type: "post",
                url: "computerbandedit.ashx",
                data: {
                    'mode': 'deleteband',
                    'computerid': computerid,
                    'mainid': pid
                },
                dataType: 'JSON',
                success: function (data, status) {
                    if (status == "success") {
                        if (data.result == true) {
                                    

                            $('#cardtable'+pid).bootstrapTable("refresh", {
                                silent: true //静态刷新
                            });
                            toastr.success(<%=GetQuoteString("C0005") %>);
                        }
                        else {
                            toastr.error(<%=GetQuoteString("C0006") %>);
                        }
                    }
                },
                error: function () {
                    toastr.error(<%=GetQuoteString("C0006") %>);
                },
                complete: function () {

                }

            });
            }
            });//then
            }


            $("#sava-mainpc-btn").click(function () {
                $('#myModalselectmainpc').modal('hide');
                var sels = $("#tb_selectmainpc").bootstrapTable('getSelections');



                var computercodemain = null;
                sels.forEach(function (row) {
                    computercodemain = row.ComputerID;
                });

                if(computercodemain==null)
                {
                    toastr.info(<%=GetQuoteString("D0113") %>);
                    return;
                }

               
                $.ajax({
                    type: "post",
                    url: "computerbandedit.ashx",
                    data: {
                        "mode": 'addmain',
                        "computerid": computercodemain
                    },
                    dataType: 'JSON',
                    success: function (data, status) {
                        if (status == "success") {
                            if (data.result == true) {

                                $('#tb_computerband').bootstrapTable("refresh", {
                                    silent: true //静态刷新
                                });
                                toastr.success(<%=GetQuoteString("C0005") %>);
                            }
                            else {
                                toastr.error(<%=GetQuoteString("C0006") %>);
                            }
                        }
                    },
                    error: function () {
                        toastr.error(<%=GetQuoteString("C0006") %>);
                    },
                    complete: function () {
                        
                    }

                });
            });

            $("#sava-bandpc-btn").click(function () {
                $('#myModalselectbandpc').modal('hide');

                var computerid = $("#myModalselectbandpc input[name='edtComputerid']").val();

                var sels = $("#tb_selectbandpc").bootstrapTable('getSelections');


                
                var computercodemain = "";
                sels.forEach(function (row) {
                    computercodemain =computercodemain+ row.ComputerID+ ",";
                });
                

                if(computercodemain=="")
                {
                    toastr.info(<%=GetQuoteString("D0113") %>);
                    return;
                }

               
                $.ajax({
                    type: "post",
                    url: "computerbandedit.ashx",
                    data: {
                        "mode": 'addsub',
                        "computerid": computerid,
                        "subids": computercodemain
                    },
                    dataType: 'JSON',
                    success: function (data, status) {
                        if (status == "success") {
                            if (data.result == true) {

                                $('#cardtable' + computerid).bootstrapTable("refresh", {
                                    silent: true //静态刷新
                                });
                                toastr.success(<%=GetQuoteString("C0005") %>);
                            }
                            else {
                                toastr.error(<%=GetQuoteString("C0006") %>);
                            }
                        }
                    },
                    error: function () {
                        toastr.error(<%=GetQuoteString("C0006") %>);
                    },
                    complete: function () {
                        
                    }

                });
            });

          

            $('#myModalselectmainpc').on('hidden.bs.modal', function () {
                $("#tb_selectmainpc").bootstrapTable('destroy');
            });

            $('#myModalselectbandpc').on('hidden.bs.modal', function () {
                $("#tb_selectbandpc").bootstrapTable('destroy');
            });



            $("#btn_clear").click(function () {
                $("#txt_search_pccode").val("");
                $("#txt_search_name").val("");
                $("#txt_search_memo").val("");
                $("#txt_search_group").val("");
            })

            $("#btn_query").click(function () {
                $('#tb_computer').bootstrapTable('refresh', { offset: 1 });
            })

            $("#btncard_clear").click(function () {
                $("#txt_search_text").val("");
            })

            $("#btncard_query").click(function () {
                $('#tb_selectcard').bootstrapTable('refresh', { offset: 1 });
            })
            $("#btngroup_clear").click(function () {
                $("#txt_searchgroup_text").val("");
            })

            $("#btngroup_query").click(function () {
                $('#tb_selectgroup').bootstrapTable('refresh', { offset: 1 });
            })

            

            toastr.options.positionClass = 'toast-top-center';
        </script>
</body>
</html>
