<%@ Page Language="C#" AutoEventWireup="true" CodeFile="studentlistclswise.aspx.cs" MasterPageFile="~/module/dashboardPage.master" Inherits="module_studentlistclswise" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
       var staddress = "";
       var ddyear1 = "";
      var  ddyear2 = "";
       var dtyear1 = "";
      var  dtyear2 = "";
      var  stryr = ""; var staddress1 = "";
        $(document).ready(function () {
            let today2 = new Date().toISOString().substr(0, 10);

            document.querySelector("#dp-5").value = today2;
            let today3 = new Date().toISOString().substr(0, 10);

            document.querySelector("#dp-6").value = today3;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "studentlistclswise.aspx/PopulateDropDownList8",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlyears3]').empty();
                    //var currentdt = new Date();
                    //var cuurentyr = currentdt.getFullYear();
                    //var prevyr = currentdt.setFullYear(currentdt.getFullYear() - 1);
                    $('select[id$=ddlyears3]').append("<option value='0'>Select Year</option>");
                 
                    $.each(result.d, function (key, value) {
                        ddyear1 = value.DeptName;
                        ddyear2 = value.year1; 
                        dtyear1 = new Date(ddyear1);
                        dtyear2 = new Date(ddyear2);
                           
                        stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();
                          
                        $('select[id$=ddlyears3]').append($("<option data-toggle='tooltip' data-placement='top' title='" + stryr + "'></option>").val(value.DeptId).html(stryr));
                        //console.log(value.DeptName);
                    });
                    // $('select[id$=ddlyears]').val('0').change();
                    //$('select[id$=cat] option:eq(0)').attr("selected", true);
                    //  $('select[id$=ddlclassty]').selectpicker('refresh');
                    //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }

            }); 
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "studentlistclswise.aspx/PopulateDropDownListCaste",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlcastes]').empty();
                    $('select[id$=ddlcastes]').append("<option value='0'>Select Category</option>");
                    $.each(result.d, function (key, value) {
                        var dd = value.DeptName;


                        $('select[id$=ddlcastes]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                        //console.log(value.DeptName);
                    });
                    // $('select[id$=ddlclass]').val('0').change();
                    //$('select[id$=cat] option:eq(0)').attr("selected", true);
                    //  $('select[id$=ddlclassty]').selectpicker('refresh');
                    //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                },
                error: function ajaxError(result) {
                    console.log(result.status + ' : ' + result.statusText);
                }

            });
            $('select[id$=ddlyears3]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "studentlistclswise.aspx/PopulateDropDownList5",
                    data: "",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=clasrch1]').empty();
                        $('select[id$=clasrch1]').append("<option value='0'>Select class</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=clasrch1]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        // $('select[id$=ddlclass]').val('0').change();
                        //$('select[id$=cat] option:eq(0)').attr("selected", true);
                        //  $('select[id$=ddlclassty]').selectpicker('refresh');
                        //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                    },
                    error: function ajaxError(result) {
                        console.log(result.status + ' : ' + result.statusText);
                    }

                });
            }); 
            $('select[id$=clasrch1]').change(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "studentlistclswise.aspx/PopulateDropDownList6",
                    data: "{clids :'" + $('select[id$=clasrch1]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddldivs]').empty();
                        $('select[id$=ddldivs]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=ddldivs]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=ddldivs]').val('0').change();
                        //$('select[id$=cat] option:eq(0)').attr("selected", true);
                        //  $('select[id$=ddlclassty]').selectpicker('refresh');
                        //  hdndoc=$('select[id$=cat] option:eq(1)').val();
                    },
                    error: function ajaxError(result) {
                        console.log(result.status + ' : ' + result.statusText);
                    }

                });
                
            });
            getdatas();
        });
        function getdatas() {
            $.ajax({
                type: "POST",
                url: "studentlistclswise.aspx/GetData",
                contentType: "application/JSON; charset=utf-8",

                datatype: "JSON",
                success: function (data) {
                    var table = $('#Table1').DataTable();
                    data = JSON.parse(data.d);
                    table.clear();

                    for (var i = 0, count = 1; i < data.length; i++, count++) {
                        staddress = data[i].resiaddrss + "," + data[i].cityname + "," + data[i].stname + "," + data[i].pin;
                        ddyear1 = data[i].fromdate;
                        ddyear2 = data[i].todate;
                        dtyear1 = new Date(ddyear1);
                        dtyear2 = new Date(ddyear2);
                        stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();
                        var fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        table.row.add([
                             data[i].studid, fullname,data[i].gender,staddress,data[i].email,stryr,data[i].classname,data[i].divname,data[i].admdate,data[i].studdob,data[i].mobile1,data[i].mobile2,data[i].feename,data[i].status,data[i].isprovisional,
                           

                        ]).draw(true);

                    }
                }
            });
        } 
        function ExportData() {
         
            var obj = {};
            obj.clasr = $("select[id$=clasrch1]").val();
            obj.division = $("select[id$=ddldivs]").val();
            obj.acdyear = $('select[id$=ddlyears3]').val();
            obj.castes = $("select[id$=ddlcastes]").val();
            obj.genders = $("select[id$=ddlgender]").val();
            obj.stdate = $("#dp-5").val();
            obj.enddt = $("#dp-6").val();
            if($('select[id$=ddlyears3]').val() != "0"){
                if($("select[id$=ddldivs]").val() != "0"){
                    if($('select[id$=clasrch1]').val() != "0"){
                        $.ajax({
                            url: 'studentlistclswise.aspx/Export',
                            method: 'post',
                            contentType: 'application/json;charset=utf-8',
                            data : JSON.stringify(obj),
                            dataType: 'json',
                            success: function (_data) {
                                table = $('#Table1').DataTable();
                               table.destroy();
                                if (_data.d != "") {
                                    _data = JSON.parse(_data.d);
                                 
                                }
                                var table = $('#Table1').DataTable({

                                    "order": [[ 0, "asc" ]],
                                    "ordering": false,
                                    "pageLength": 10,
                                    "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
                                    "dom": 'lBfrtip',
                                    buttons: [
                                    {
                                        extend: 'excelHtml5',
                                        text: 'Export to Excel',
                                        title: 'Student List',
                                        download: 'open',
                                        orientation: 'landscape',
                                        exportOptions: {
                                         columns: ':visible'
                                        }
                                    }],
                                    "columns": [
                                             { "width": "10%" },
                                             { "width": "8%" },
                                             { "width": "8%" },  { "width": "5%" },
                                             { "width": "8%" },{ "width": "8%" },
                                             { "width": "8%" },
                                             { "width": "10%" },
                                             { "width": "10%" }, 
                                             { "width": "8%" },{ "width": "8%" },
                                            { "width": "8%" },{ "width": "8%" },{ "width": "8%" },{ "width": "8%" }
                                          
                                    ]
                                });

                            // $('#Table1').DataTable().clear().draw();

                                for (var i = 0; i < _data.length; i++) { 
                                   
                                 
                                    ddyear1 = _data[i].fromdate;
                                    ddyear2 = _data[i].todate;
                                    dtyear1 = new Date(ddyear1);
                                    dtyear2 = new Date(ddyear2);
                                    stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();
                                    fullname = _data[i].title + "." + _data[i].fname + " " + _data[i].mname + " " + _data[i].lname;
                               staddress1 = _data[i].resiaddrss + "," + _data[i].city + "," +","+ _data[i].state + _data[i].pin;
                                    table.row.add([
                   
                              _data[i].studid, fullname,_data[i].gender,staddress1,data[i].email, stryr,_data[i].classname,_data[i].divname,_data[i].admdate,data[i].studdob,data[i].mobile1,data[i].mobile2,_data[i].feename,data[i].status,data[i].isprovisional,
                   

                                    ]).draw(false);
                                } 
                                //var buttons = table.buttons( ['.edit', '.delete'] );

                                //if ( table.rows( { selected: true } ).indexes().length === 0 ) {
                                //    buttons.disable();
                                //}
                                //else {
                                //    buttons.enable();
                                //}
                            },
                            error: function () {
                               
                              
                                noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                                setTimeout(function () { $.noty.closeAll(); }, 3000);
                            }
                        });
                    }else{
                        noty({ text: 'Please Select Class', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                    }
                }
                else{
                    noty({ text: 'Please Select Division', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                } 
            }else{
                noty({ text: 'Please Select Year', layout: 'topRight', type: 'information' });
                setTimeout(function () { $.noty.closeAll(); }, 3000);
            }
           
        } 
        function getdata13(){
            var obj1 = {};
            obj1.clasr = $("select[id$=clasrch1]").val();
            obj1.division = $("select[id$=ddldivs]").val(); 
            obj1.acdyear = $('select[id$=ddlyears3]').val();
            obj1.castes = $("select[id$=ddlcastes]").val();
            obj1.genders = $("select[id$=ddlgender]").val();
            obj1.stdate = $("#dp-5").val();
            obj1.enddt = $("#dp-6").val();
            $.ajax({
                type: "POST",
                url: "studentlistclswise.aspx/GetDataSearch",
                contentType: "application/JSON; charset=utf-8",
                data : JSON.stringify(obj1),
                datatype: "JSON",
                success: function (data) {
                    if(data.d != "")
                    {
                        var table = $('#Table1').DataTable();
                        data = JSON.parse(data.d);
                        table.clear().draw();

                        for (var i = 0, count = 1; i < data.length; i++, count++) {
                            staddress = data[i].resiaddrss + "," + data[i].cityname + "," + data[i].stname + "," + data[i].pin;
                            ddyear1 = data[i].fromdate;
                            ddyear2 = data[i].todate;
                            dtyear1 = new Date(ddyear1);
                            dtyear2 = new Date(ddyear2);
                            stryr = dtyear1.getFullYear() + "-" + dtyear2.getFullYear();
                            var fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                            table.row.add([
                                 data[i].studid,fullname,data[i].gender,staddress,data[i].email,stryr, data[i].classname, data[i].divname,data[i].admdate,data[i].studdob,data[i].mobile1,data[i].mobile2,data[i].feename,data[i].status,data[i].isprovisional,
                           

                            ]).draw(true);

                        }
                    }
                }
            });
        }
    </script>
<div class="page-wrapper">
			<div class="page-content">
				<div class="row">
					<div class="col-md-12 mx-auto">
                        <div class="card">
					<div class="card-body">
						<div class="card-title d-flex align-items-center">

							<h6>Student List</h6>
						</div>
						<hr/>
                        <form class="row g-2">
                        <div class="col-md-2">
						  <label>Year</label>
							<select class="form-select mb-3" id="ddlyears3" aria-label="Default select example">
						
							</select>
						</div>
						
                        <div class="col-md-2">
						  <label>Class</label>
							<select class="form-select mb-3" id="clasrch1" aria-label="Default select example">
						
							</select>
						</div> 
                               <div class="col-md-2">
						  <label>Division</label>
							<select class="form-select mb-3" id="ddldivs" aria-label="Default select example">
						
							</select>
						</div> 
                            <div class="col-md-2">
						  <label>Caste</label>
							<select class="form-select mb-3" id="ddlcastes" aria-label="Default select example">
						
							</select>
						</div> 
                            <div class="col-md-2">
                            <label>Gender</label>
							<select class="form-select mb-3" id="ddlgender" aria-label="Default select example">
						        <option value="">Select Gender</option>
                                <option value="male">Male</option>
                                 <option value="female">Female</option>
							</select>
                            </div> 
						<div class="col-md-2">
                            <label>From date</label>
							<input class="form-control mb-3" id="dp-5" type="date"
								aria-label="default input example" />

                            </div> 
                            <div class="col-md-2">
                                	<label>To date</label>
							<input class="form-control mb-3" id="dp-6" type="date"
								aria-label="default input example" />
                                </div>
                         <div class="col-md-1" style="margin-top: 30px;">
						<button type="button" onclick="getdata13();" class="btn btn-primary">Search</button>
						
										
					   </div>
                            </form>

                          <div class="col-md-12 mx-auto">
                              <div class="card">
							<div class="card-body">
                         <div class="btn-group pull-right" style="float:right">
                                        <button class="btn btn-danger dropdown-toggle" style="display:none" data-toggle="dropdown"><i class="fa fa-bars"></i> Export Data</button>
                                        <ul  class="has-arrow">
                                           
                                            <li><%--<a href="#" onclick ="$('#dataemp').tableExport({type:'excel',escape:'false'});"> Student Installment(Excel)</a>--%><a href="#" onclick="ExportData();">Student List(Excel)</a></li>
                                          
                                           <%-- <li><a href="#" onclick ="$('#tt').tableExport({type:'pdf',escape:'false'});"> PDF</a></li>--%>
                                        </ul>
                                    </div>
                              </div>
                                  </div> 
                              </div> 
                        <div class="col-md-12 mx-auto">
                           <div class="col-md-12 mx-auto">
						<div class="card">
							<div class="card-body">
                                <div style="overflow-x:scroll">
								<table class="table mb-0"  id="Table1">
									<thead  class="table table-striped table-bordered ">
										<tr>
											
										
											<th scope="col">Stud ID</th>
											<th scope="col">Student Name</th>
                                            <th scope="col">Gender</th>
                                            <th scope="col">Address</th>
                                             <th scope="col">Email ID</th>
                                            <th scope="col">Year</th>
											<th scope="col">Class</th>
											<th scope="col">Division</th>
                                          
                                            <th scope="col">Admission Date</th>
                                             <th scope="col">Date Of Birth</th>
                                            <th scope="col">Mobile1</th>
                                             <th scope="col">Mobile2</th>
                                            <th scope="col">Caste</th>
                                            <th scope="col">Status</th>
                                              <th scope="col">IsProvisional</th>
										</tr>
									</thead>
									<tbody>
										
									
									</tbody>
								</table>
                                    </div>
							</div>
						</div>
					
					</div>
                        </div> 
                            </div> 
                      
                
     <div class="col">
        	<div class="modal fade" id="exampleLargeModal6" tabindex="-1" data-bs-backdrop="static" aria-hidden="true">
			<div class="modal-dialog modal-xl">
				<div class="modal-content">
					<div class="modal-header">
                      	<h5 class="modal-title">Assign Student</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" id="Button1" aria-label="Close"></button>
                        </div>
                    	<div class="modal-body">
                            <div class="row g-2">
					
							<div class="col-md-5">
						
							<select class="form-select mb-3" id="ddstud" aria-label="Default select example">
						
							</select>
						</div>
                            	
					
							<div class="col-md-5">
						
								<select class="form-select mb-3" id="ddlpkg" aria-label="Default select example">
					
							</select>
						</div>
					  

				

					
					<div class="col-md-1" style="margin-top: 1vh;">
						<button type="button" onclick="updatepkg1()" class="btn btn-primary">Update</button>
						
										
					   </div>

                            </div> 
                            </div>
                    </div> 
                </div> 
                </div>
    </div>
     </div> 
                    </div>
                        </div> 
                    </div> 
    </asp:Content>