<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true" CodeBehind="RaporIzlemeListesi.aspx.cs" Inherits="Giza.Web.Moduller.RaporIzleme.RaporIzlemeListesi" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderHeader" runat="server">
    <%--<%@ Register TagPrefix="ezUc" TagName="DuyurularYatay" Src="~/UserControls/ucDuyurularYatay.ascx" %>--%>

    <link href="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/bootstrap-table.min.css")%>" rel="stylesheet" />
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/bootstrap-table.min.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/locale/bootstrap-table-tr-TR.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/export/bootstrap-table-export.min.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/export/tableExport.min.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/filter-control/bootstrap-table-filter-control.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/cookie/bootstrap-table-cookie.js")%>"></script>
    <link href="<%=Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-select/dist/css/bootstrap-select.css") %>" />
    <script src="<%=Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-select/dist/js/bootstrap-select.js") %>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/cookie/bootstrap-table-cookie.js")%>"></script>
    <link href="<%= Page.ResolveUrl("~/Content/vendors/bootgrid/jquery.bootgrid.css") %>" rel="stylesheet" />
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-select/dist/js/i18n/defaults-tr_TR.min.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/input-mask/input-mask.js") %>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/jquery-autoNumeric/autoNumeric.js") %>"></script>

    <link href="<%=Page.ResolveUrl("~/Content/vendors/daterangepicker/daterangepicker.css")%>" rel="stylesheet" />
    <script src="<%=Page.ResolveUrl("~/Content/vendors/daterangepicker/moment.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/daterangepicker/daterangepicker.js") %>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/js/jsPDF/jspdf.min.js") %>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/js/jsPDF/jspdf.plugin.autotable.js") %>"></script>

    <link href="<%= Page.ResolveUrl("~/Content/css/imageviewer.css")%>" rel="stylesheet" />
    <script src="<%= Page.ResolveUrl("~/Content/js/imageviewer/imageviewer.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/js/imageviewer/imageviewer.min.js")%>"></script>

    <link href="<%=Page.ResolveUrl("~/Content/css/giza.css")%>" rel="stylesheet" />
    <style type="text/css">
        .gallery-items {
            float: left;
            height: 350px;
        }

        .bs-item-icon {
            font-size: 65px;
            margin: 0px auto;
            display: block;
            padding: 10px 0px 10px 0px;
            color: #FFF;
            width: 100%;
        }

        .bs-item-title {
            height: 35px;
            text-align: center;
            line-height: 20px;
            color: #014643 !important;
        }

        .bs-item {
            margin-right: 10px;
            margin-bottom: 10px;
            margin-left: 10px;
            padding-left: 0px;
            padding-right: 0px;
            position: static !important;
        }


        .border1 {
            border-radius: 30px;
            border: 2px solid #808080;
            padding: 20px;
            width: 100%;
        }

            .border1 h1 {
                text-align: center;
                margin-top: -10px;
                height: 20px;
                line-height: 20px;
                font-size: 15px;
            }

                .border1 h1 span {
                    background-color: white;
                }

        .profile-img-container {
            position: relative;
        }

            .profile-img-container img {
                width: 100%;
            }
            /* remove if using in grid system */


            .profile-img-container a {
                display: block;
                position: absolute;
                opacity: 0.5;
                top: 0;
                left: 0;
                bottom: 0;
                right: 0;
                text-align: center;
                color: inherit;
                font-size: 60px;
            }

        .bootstrap-table > fixed-table-toolbar > search > input {
            width: 100%;
        }

        .ci-avatar {
            max-height: 50% !important;
            height: 50% !important;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            DateRangePickerLoad();
        });

        function DateRangePickerLoad() {

            //BU AY
            var start = moment().startOf('month');
            var end = moment().endOf('month');

            //BU YIL
            //var start = moment("01 01 " + moment().year(), "D MMMM YYYY");
            //var end = moment("01 01 " + (moment().year() + 1), "D MMMM YYYY").subtract(1, 'days'); //1 gün çıkar

            function cb(start, end) {
                $('.reportrange span').html(start.format('D MMMM YYYY') + ' - ' + end.format('D MMMM YYYY'));
            }

            $('.reportrange').daterangepicker({
                startDate: start,
                endDate: end,
                ranges: {
                    'Bugün': [moment(), moment()],
                    'Dün': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                    'Son 7 Gün': [moment().subtract(6, 'days'), moment()],
                    'Son 30 Gün': [moment().subtract(29, 'days'), moment()],
                    'Bu Ay': [moment().startOf('month'), moment().endOf('month')],
                    'Geçen Ay': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                    'Bu Sene': [moment("01 01 " + moment().year(), "D MMMM YYYY"), moment("01 01 " + (moment().year() + 1), "D MMMM YYYY").subtract(1, 'days')]

                    //var start = moment("01 01 " + moment().year(), "D MMMM YYYY"); //BU AY
                }
            }, cb);

            cb(start, end);

            $('.reportrange').on('apply.daterangepicker', function (ev, picker) {
                //ToList();
            });

        };


        function ButonIslemYap(raporId, secilenSatirDegeri, hangiButon) {
            swal({
                title: "İşleme devam etmek istiyor musunuz?",
                text: "Devam ederseniz değişiklik geri alınamaz",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Devam Et",
                cancelButtonText: "İptal",
                closeOnConfirm: true,
                closeOnCancel: true
            }, function (isConfirm) {
                if (isConfirm) {
                    notify("İşlem Yapılıyor...", "info");
                    var databaseName = '<%=HttpContext.Current.Session["SeciliSirket"] == null ? "" : HttpContext.Current.Session["SeciliSirket"].ToString()%>';
                    $.ajax({
                        type: "POST",
                        url: '<%=Page.ResolveUrl("~/DataService.asmx/ButonSqlCalistir")%>',
                        data: { raporId: raporId, secilenSatirDegeri: secilenSatirDegeri, hangiButon: hangiButon, databaseName: databaseName },
                        success: function (result) {
                            var gelenStatus = result.status;
                            var gelenMesaj = result.message;

                            if (gelenStatus == 1) {
                                $("#table").bootstrapTable('refresh');
                                notify(gelenMesaj, "success");
                                location.reload();
                            }
                            else
                                if (gelenStatus == 0)
                                    notify(gelenMesaj, "warning");

                            console.log(result.sqlscript);
                        },
                        error: function (e) {
                            notify("Kayıt silinirken hata oluştu. Hata:" + e.responseText.substring(0, 200) + "...", "danger", "", 10000);
                        }
                    });
                } else {
                    notify("İşlem çalıştırılmadı", "info");
                }
            });
        }
        function GridRenkAyarla() {
            $('#table').on('click-row.bs.table', function (e, row, $element) {
                //here the hidden column is readable :)
                console.log(row.cust_id);
            });
        }
        function rowStyle(row, index) {
            var backcolor = "";
            var color = "";
            if (row.RENKKODU != null) {

                var splited = row.RENKKODU.split(';')
                backcolor = splited[0];
                color = splited[1];
            }
            return {
                css: { "background-color": backcolor, "color": color, }
            };
        }
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBreadcrumbs" runat="server">
    <ol class="breadcrumb" style="margin-bottom: 5px;">
        <asp:Literal runat="server" ID="ltrlRaporYolu"></asp:Literal>
    </ol>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderMain" runat="server">
    <asp:HiddenField ID="hdnToList" ClientIDMode="Static" runat="server" />
    <%--    <asp:HiddenField ID="hdnDatabaseName" ClientIDMode="Static" runat="server" />--%>
    <asp:HiddenField ID="hdnSelectedTableName" ClientIDMode="Static" runat="server" />
    <asp:HiddenField ID="hdnMasterRaporId" ClientIDMode="Static" runat="server" />
    <asp:HiddenField ID="hdnFiltreZorunluMu" ClientIDMode="Static" runat="server" />
    <asp:HiddenField ID="hdnFiltreGirildiMi" Value="0" ClientIDMode="Static" runat="server" />
<%--    <div class="card">
        <div class="card-header">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td>
                        <ezUc:DuyurularYatay ID="DuyurularYatay" runat="server" />
                    </td>
                </tr>
            </table>
        </div>
    </div>--%>

    <div id="cardRaporArama" class="card" runat="server">
        <div class="card-header">
            <h2 style="text-align: center">Rapor Arama</h2>
        </div>
        <div class="card-body card-padding">
            <%--            <div id="toolbar" style="padding-right: 25px; padding-left: 5px">
                <div id="btnYenile" class="btn bgm-teal waves-effect" onclick="AramaTemizle();">Aramayı Temizle</div>
            </div>--%>
            <div style="overflow-x: auto;">
                <table id="tblRaporlar"
                    data-toggle="table"
                    data-toolbar="#toolbar"
                    data-ajax="getRaporListesi"
                    data-search="true"
                    data-search-align="center"
                    data-show-refresh="false"
                    data-show-toggle="false"
                    data-show-columns="false"
                    data-show-export="false"
                    data-minimum-count-columns="2"
                    data-show-pagination-switch="false"
                    data-pagination="false"
                    data-id-field="Id"
                    data-locale="tr-TR"
                    data-show-footer="false"
                    data-side-pagination="server"
                    data-sort-name="RaporAdi"
                    data-sort-order="asc">
                    <thead>
                        <tr>
                            <th data-formatter="grupIzle" data-field="GrupAdi" data-sortable="true">Grup Adı</th>
                            <th data-formatter="raporIzle" data-field="RaporAdi" data-sortable="true">Rapor Adı</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function getRaporListesi(params) {
            var limit = params.data.limit;
            var offset = params.data.offset;
            var search = params.data.search;
            var sort = params.data.sort;
            var order = params.data.order;
            $.ajax({
                url: "<%=Page.ResolveUrl("~/DataService.asmx/GetRaporveRaporGrupList")%>",
                data: { limit: limit, offset: offset, search: search, sort: sort, order: order },
                success: function (result) {
                    params.success({
                        total: result.total,
                        rows: result.rows
                    });
                }
            });
        }


        function raporIzle(value, row) {
            if (row.Turu == "Rapor") {
                return " <a title='Rapor İzleme' class=\"btn bgm-blue waves-effect\" href='RaporIzlemeListesi.aspx?RaporGrupId=" + row.GrupId + "&ToListRaporId=" + row.RaporId + "'\"> <span style=\"width:6px \" class=\"zmdi zmdi-link c-white\"> </span></a> " + row.RaporAdi;
            }
        }

        function grupIzle(value, row) {
            if (row.Turu == "Grup")
                return " <a title='Grup İzleme' class=\"btn bgm-deeporange waves-effect\" href='RaporIzlemeListesi.aspx?RaporGrupId=" + row.GrupId + "'\"> <span style=\"width:6px \" class=\"zmdi zmdi-link c-white\"> </span></a> " + row.GrupAdi;
        }
    </script>



    <div id="cardRaporGorselleri" class="card" runat="server" visible="false">
        <div class="card-body card-padding">
            <div class="row">
                <div class="col-sm-1">

                    <asp:Literal ID="ltrlGeri" runat="server"></asp:Literal>

                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="contacts c-profile clearfix row">
                            <asp:Repeater ID="rptDokumanlar" runat="server">
                                <ItemTemplate>
                                    <div class="col-md-2 col-sm-4 col-xs-6">
                                        <div class="c-item">
                                            <a href="" class="ci-avatar">
                                                <img id="imgDokumanItem_<%#Eval("Id")%>" onclick="DokumanGoruntule(<%#Eval("Id")%>); return false;" src="<%#Eval("KucukVeri") %>" data-buyukdata="<%#Eval("BuyukVeri") %>" />

                                            </a>

                                            <div class="c-footer">
                                                <button type="button" class="waves-effect" onclick="DokumanGoruntule(<%#Eval("Id")%>)" style="background-color: #cc3838; color: #FFF;"><i class="zmdi zmdi-search"></i>Görüntüle</button>
                                            </div>
                                        </div>
                                    </div>
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">

                <div id="FilterDiv" runat="server"></div>
            </div>
        </div>
    </div>







    <div id="divMevcutRaporBilgisi" runat="server">
    </div>



    <div id="divRaporGruplari" runat="server">
    </div>

    <div id="divRaporlar" runat="server">
    </div>

    <div id="RaporGrupButonlariDiv" runat="server">
    </div>

    <div id="divRaporIzleme" visible="false" class="card" runat="server">
        <div class="card-body card-padding">
            <div id="ToListDiv" runat="server" style="overflow-x: auto;">
                <table id="table" class="table"
                    data-height=""
                    data-ajax="ajaxRequest"
                    data-cache="true"
                    data-side-pagination="server"
                    data-pagination="true"
                    data-show-refresh="false"
                    data-toolbar="#toolbar"
                    data-search="false"
                    data-search-align="left"
                    data-show-columns="false"
                    data-show-export="true"
                    data-show-toggle="false"
                    data-show-footer="false"
                    data-show-pagination-switch="false"
                    data-cookie="false"
                    data-cookie-id-table="saveUserDefinedReportId"
                    data-striped="false"
                    data-hover="false"
                    data-mobile-responsive="true"
                    data-check-on-init="true"
                    data-filter-control="false"
                    data-advanced-search="false"
                    data-id-table="advancedTable"
                    data-page-number="1"
                    data-page-size="10"
                    data-page-list="[10, 25, 50, 100, 200, 500, Tumu]"
                    data-locale="tr-TR"
                    data-id-field="Id"
                    data-sort-name=""
                    data-sort-order=""
                    data-export-types="['excel', 'pdf']"
                    data-export-options='{
                      "fileName": "Rapor",
                      "worksheetName": "RaporSayfa1",
                      "htmlContent" : "true",
                      "jspdf": {
                        "autotable": {
                          "startY": 20,
                          "bodyStyles": {"valign": "top"},
                          "styles": {"overflow": "linebreak", "rowHeight": 20, "fontSize": 10, "font": "helvetica"},
                          "headerStyles": {"fillColor": [41, 128, 185]},
                          "tableWidth": "wrap"
                        }
                      }
                    }'
                    data-row-style="rowStyle">
                    <thead>
                        <tr></tr>
                    </thead>
                </table>

            </div>

        </div>
    </div>


    <div class="card" id="cardRaporBilgi" visible="false" runat="server">

        <div class="card-body card-padding">
            <div class="row">
                <asp:Literal ID="ltrlRaporBilgi" runat="server"></asp:Literal>

            </div>

        </div>
    </div>


    <script type="text/javascript">

        function ajaxRequest(params) {
            var hdnFiltreZorunluMu = $('#hdnFiltreZorunluMu').val();
            if (hdnFiltreZorunluMu == "1") {
                FiltreAlanlariniKontrolEt();
                var hdnFiltreGirildiMi = $('#hdnFiltreGirildiMi').val();
                if (hdnFiltreGirildiMi == '0') return;
            }
            console.log(params.data);
            var limit = params.data.limit;
            var offset = (params.data.offset / limit) + 1;
            var search = params.data.search;
            var sort = params.data.sort;
            var order = params.data.order;
            var databaseName = '<%=HttpContext.Current.Session["SeciliSirket"] == null ? "" : HttpContext.Current.Session["SeciliSirket"].ToString()%>';
            //todo:StaticVeritabanıAdi
            //var databaseName = 'Projeler';
            var selectedTableName = $('#<%=hdnSelectedTableName.ClientID%>').val();
            var searchText = $("#<%=hdnToList.ClientID%>").val();

            var masterRaporId = '<%=Request.QueryString.Get("MasterRaporId")%>';
            var masterRaporValue = '<%=Request.QueryString.Get("MasterRaporValue")%>';
            var altRaporBtn = '<%=Request.QueryString.Get("altRaporBtn")%>';

            $.ajax({
                url: "<%=Page.ResolveUrl("~/DataService.asmx/GetDynamicReportList")%>",
                data: { limit: limit, offset: offset, search: search, sort: sort, order: order, databaseName: databaseName, selectedTableName: selectedTableName, searchText: searchText, masterRaporId: masterRaporId, masterRaporValue: masterRaporValue, altRaporBtn: altRaporBtn },
                success: function (result) {
                    console.log("ajaxRequest " + result.gridsql);
                    var list = new Array();
                    $.each(result.rows, function (index, value) {
                        var obj = new Object();
                        $.each(value, function (i, v) {
                            //parametreli gönderilen kolon adlarını süzmek için
                            var keyValue = v.Key;
                            var splited = keyValue.split(':');
                            if (splited.length > 1) {
                                keyValue = splited[0];
                            }
                            obj[keyValue] = v.Value;
                        });
                        list.push(obj);

                    });
                    params.success({
                        total: result.total,
                        rows: list
                    });

                    $('[data-toggle="tooltip"]').tooltip();
                    GridRenkAyarla();
                    //$("#table").bootstrapTable('hideColumn', 'RENKKODU');
                    $("#table").bootstrapTable();
                }
            });

        }

    </script>
    <script>

        function FiltreAlanlariniKontrolEt() {
            var data = $('#AramaDiv > .col-sm-3 > .form-group > .fg-line > input');
            var doluvarmi = false;

            $.each(data, function (index, comp) {

                var deger = $(comp).val();

                if (deger != '') {
                    doluvarmi = true;
                }
            })

            if (!doluvarmi) {
                $('#hdnFiltreGirildiMi').val('0');
                $("#table tbody tr").html('');
                notify("Lütfen filtre alanlarını doldurunuz.", "info");

            } else {
                $('#hdnFiltreGirildiMi').val('1');
            }
        }


        function ToList() {
            var hdnFiltreZorunluMu = $('#hdnFiltreZorunluMu').val();
            if (hdnFiltreZorunluMu == "1") {
                FiltreAlanlariniKontrolEt();
                var hdnFiltreGirildiMi = $('#hdnFiltreGirildiMi').val();
                if (hdnFiltreGirildiMi == '0') return;
            }
            var searchText = "";
            //var data = $('#SearchDiv > input');
            var data = $('#AramaDiv > .col-sm-3 > .form-group > .fg-line > input');
            var array = new Array();
            $.each(data, function (index, input) {
                var text = $(input).val();
                var inputName = input.name;

                //var splitedinputName = inputName.split(':');
                //var splitkolonadi = splitedinputName[0].split(',');
                //if (splitkolonadi.length> 1) {
                //    inputName = splitkolonadi[0];
                //}


                if (text != "") {
                    var tipi = $(input).data('tipi'); //className.split("form-control input-sm fg-input");
                    if (tipi != "") {
                        if (tipi == "decimal") {
                            text = text.trim();
                            var parseText = text.replace(",", ".");
                            text = parseText;
                        }
                        else if (tipi == "datetime") {

                            var ikiliTarih = text;
                            var islenenText = '';
                            //var baslangicTarihi = text.split('-')[0].trim();
                            //var bitisTarihi = text.split('-')[1].trim();

                            //var baslangicTarihi = $(input).data('daterangepicker').startDate._i
                            //var bitisTarihi = $(input).data('daterangepicker').endDate._i


                            for (var Ind = 0; Ind < 2; Ind++) {
                                islenenText = ikiliTarih.split('-')[Ind].trim();
                                var column = islenenText.split(".");
                                column.reverse();
                                var parseText = "";
                                for (var i = 0; i < column.length; i++) {
                                    if (i == 0)
                                    { parseText = column[i]; }
                                    else
                                    { parseText = parseText + "-" + column[i]; }
                                }

                                if (Ind == 0) {
                                    text = parseText;
                                } else {
                                    text += " / " + parseText
                                }
                            }
                        }
                    }
                    array.push({ kolonAdi: inputName, kolonDegeri: text.toUpperCase(), tip: tipi })
                }
            });
            if (array.length != 0) {

                for (var i = 0; i < array.length; i++) {
                    if (array[i].tip == "datetime") {
                        var baslangicTarihi = array[i].kolonDegeri.split('/')[0].trim();
                        var bitisTarihi = array[i].kolonDegeri.split('/')[1].trim();

                        if (i != array.length - 1) {
                            searchText = searchText + " [" + array[i].kolonAdi + "] BETWEEN '" + baslangicTarihi + "' and '" + bitisTarihi + "' AND";
                        }
                        else {
                            searchText = searchText + " [" + array[i].kolonAdi + "] BETWEEN '" + baslangicTarihi + "' and '" + bitisTarihi + "' ";
                        }
                    }
                    if (array[i].tip == "nvarchar" || array[i].tip == "varchar") {

                        if (i != array.length - 1) {
                            searchText = searchText + " UPPER([" + array[i].kolonAdi + "]) LIKE '" + "%" + array[i].kolonDegeri + "%' AND";
                        }
                        else {
                            searchText = searchText + " UPPER([" + array[i].kolonAdi + "]) LIKE '" + "%" + array[i].kolonDegeri + "%'";
                        }
                    }
                    else if (array[i].tip != "datetime" && array[i].tip != "nvarchar" && array[i].tip != "varchar") {
                        if (i != array.length - 1) {
                            searchText = searchText + " UPPER([" + array[i].kolonAdi + "]) LIKE '" + "%" + array[i].kolonDegeri + "%' AND";
                        }
                        else {
                            searchText = searchText + " UPPER([" + array[i].kolonAdi + "]) LIKE '" + "%" + array[i].kolonDegeri + "%'";
                        }
                    }
                }
                $('#hdnToList').val(searchText);
            }
            else {
                $('#hdnToList').val('');
            }
            var limit = 0;
            var offset = 1;
            var search = "";
            var sort = "";
            var order = "";
            var databaseName = '<%=HttpContext.Current.Session["SeciliSirket"] == null ? "" : HttpContext.Current.Session["SeciliSirket"].ToString()%>';
            //todo:StaticVeritabanıAdi
            //var databaseName = 'Projeler';
            var selectedTableName = $('#<%=hdnSelectedTableName.ClientID%>').val();
            var searchText = $("#<%=hdnToList.ClientID%>").val();
            var masterRaporId = '<%=Request.QueryString.Get("MasterRaporId")%>';
            var masterRaporValue = '<%=Request.QueryString.Get("MasterRaporValue")%>';
            var altRaporBtn = '<%=Request.QueryString.Get("altRaporBtn")%>';

            $.ajax({
                type: "POST",
                url: "<%=Page.ResolveUrl("~/DataService.asmx/GetDynamicReportList")%>",
                data: { limit: limit, offset: offset, search: search, sort: sort, order: order, databaseName: databaseName, selectedTableName: selectedTableName, searchText: searchText, masterRaporId: masterRaporId, masterRaporValue: masterRaporValue, altRaporBtn: altRaporBtn },
                success: function (response) {
                    console.log("ToList " + response.gridsql);
                    var data = response.rows;
                    $("#table").bootstrapTable('destroy');
                    $("#table thead tr").html('');
                    $.each(data, function (index, value) {
                        var eklenecekmi = true;
                        if (index == 0) {
                            $.each(value, function (index, property) {
                                var splited = property.Key.split(':');
                                var kolonadi = splited[0];
                                var datafield = ' data-field="' + kolonadi + '" ';

                                if (kolonadi == "RENKKODU") {
                                    eklenecekmi = false;
                                }

                                //tr etiketleri
                                var sorttabletext = "";
                                var dataformatter = "";

                                if (splited.length > 1) {

                                    var ozelliktext = splited[1];
                                    var ozellikler = ozelliktext.split(',');

                                    $.each(ozellikler, function (index, deger) {

                                        var ozellik = deger.split('=');

                                        if (ozellik.length > 1) {

                                            //'Fisno:stil=genis100,arama=evet,gizli=hayir,resim=evet,video=hayir,siralama=hayir'
                                            if (ozellik[0] == 'gizli' && ozellik[1] == "evet") {
                                                eklenecekmi = false;
                                            }

                                            if (ozellik[0] == 'siralama' && ozellik[1] == 'evet') {
                                                sorttabletext = " data-sortable='true' ";
                                            }

                                            if (ozellik[0] == 'resim' && ozellik[1] == 'evet') {
                                                dataformatter = " data-formatter='editLink' ";
                                            }

                                            if (ozellik[0] == 'video' && ozellik[1] == 'evet') {
                                                dataformatter = " data-formatter='editLinkVideo' ";
                                            }
                                        }
                                    });
                                }

                                if (eklenecekmi) {
                                    var tr = $('<th ' + datafield + sorttabletext + dataformatter + '>' + kolonadi + '</th>');
                                    $("#table thead tr").append(tr);
                                }
                                eklenecekmi = true;
                            });
                        }
                    });
                    if (data.length == 0) {
                        var tr = $('<th data-field="Sonuc" align="left">Sonuc</th>');
                        $("#table thead tr").append(tr);
                    }

                    $('#table').bootstrapTable("destroy");
                    $('#table').bootstrapTable({ showExport: 'true' });

                },
                error: function (xhr) {
                    console.log(xhr.responseText);
                }
            });
        }
        function editLink(value, row, index) {
            var row = $('#table').bootstrapTable('getData')[index];
            if (row.FileDataBase64 != null) {
                return "<a title='Resim' class=\"btn bgm-green waves-effect\" onclick=\"Preview(" + index + ")\"> <span class=\"zmdi zmdi-search c-white\"> </span> </a> ";
            } else
                return "<a title='Resim' disabled class=\"btn bgm-gray waves-effect\" onclick=\"Preview(" + index + ")\"> <span class=\"zmdi zmdi-more c-white\"> </span> </a> ";

        }

        function editCell(value, row, index) {
            return "<p style=\"text-align:right;\"> </p> ";
        }

        function editLinkVideo(value, row, index) {
            return "<a title='Video' class=\"btn bgm-green waves-effect\" onclick=\"PreviewVideo()\"> <span class=\"zmdi zmdi-videocam c-white\"> </span> </a> ";
        }


    </script>
    <div class="modal fade" id="PagePreviewListModal" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #00a9a1;">
                    <h4 class="modal-title" style="color: #FFF;">Ön İzleme</h4>
                </div>
                <div class="modal-body" style="padding: 0px;">
                    <img id="imgPreviewDocument" src="<%=Page.ResolveUrl("~/Content/img/notifications.png")%>" alt="Resim Yüklenemedi" style="width: 50%; height: 35%; margin-left: 25%;" />
                </div>
                <div class="modal-footer" style="background-color: #00a9a1;">
                    <button type="button" class="btn bgm-teal waves-effect" data-dismiss="modal">Kapat</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="PageVideoPreviewListModal" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #00a9a1;">
                    <h4 class="modal-title" style="color: #FFF;">Video Player</h4>
                </div>
                <div class="modal-body" style="padding: 0px;">
                    <video controls>
                        <source id="vidPreviewDocument" type="video/mp4" src="">
                    </video>

                </div>
                <div class="modal-footer" style="background-color: #00a9a1;">
                    <button type="button" class="btn bgm-teal waves-effect" data-dismiss="modal">Kapat</button>
                </div>
            </div>
        </div>
    </div>



    <script>

        //function Preview(index) {
        //    var row = $('#table').bootstrapTable('getData')[index];
        //    var src = '';
        //    src = 'data:image/* ;base64,' + row.FileDataBase64;
        //    document.getElementById('imgPreviewDocument').src = src;
        //    document.getElementById('imgPreviewDocument').title = escape(row.FileName);
        //    $('#PagePreviewListModal').modal('show');
        //}

        function Preview(index) {
            var row = $('#table').bootstrapTable('getData')[index];
            if (row.FileDataBase64 != null) {
                var src = 'data:image/* ;base64,' + row.FileDataBase64;
                var viewer = ImageViewer();
                viewer.show(src, src);
            } else
                notify("Seçilen kaydın resim verisi bulunmadığından görüntülenemiyor", "info");
        };

        function GrupResimGoster(cntrl) {
            var resimdata = $(cntrl).data('image');
            if (resimdata != null) {
                var viewer = ImageViewer();
                viewer.show(resimdata, resimdata);
            } else
                notify("Seçilen kaydın resim verisi bulunmadığından görüntülenemiyor", "info");

            //document.getElementById('imgPreviewDocument').src = cntrl.src;
            //document.getElementById('imgPreviewDocument').title = cntrl.title;
            //$('#PagePreviewListModal').modal('show');

        }


        function DokumanGoruntule(Id) {
            var resimdata = $("#imgDokumanItem_" + Id).data("buyukdata");
            if (resimdata != null) {
                var viewer = ImageViewer();
                viewer.show(resimdata, resimdata);
            } else
                notify("Seçilen kaydın resim verisi bulunmadığından görüntülenemiyor", "info");
        }

        function PreviewVideo() {

            if ('<%=Request.QueryString.AllKeys.Contains("ToListRaporId")%>' == 'True') {
                var id = <%=Request.QueryString.Get("ToListRaporId")%>
                        window.location = '<%=Page.ResolveUrl("~/Moduller/Rapor/VideoGoruntule.aspx") %>' + '?Id=' + id;
            }
        }
    </script>
</asp:Content>
