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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
        var studcode = "";
        var pkgcode = ""; var clsnm = "";
        var divsnm = ""; var admissionsyrs = "";
        $(document).ready(function () {
            datatable();
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "assignspackagesstud.aspx/PopulateDropDownList4",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlyears3]').empty();
                    $('select[id$=ddlyears3]').append("<option value='0'>Select Year</option>");
                    $.each(result.d, function (key, value) {
                        var ddyear1 = value.DeptName;
                        var ddyear2 = value.year1;
                        var dtyear1 = new Date(ddyear1);
                        var dtyear2 = new Date(ddyear2);
                        var 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$=ddlyears3]').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: "assignspackagesstud.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$=clasrch1]').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: "assignspackagesstud.aspx/PopulateDropDownList6",
                    data: "{clids :'" + $('select[id$=clasrch1]').val() + "'}",
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=divisrch1]').empty();
                        $('select[id$=divisrch1]').append("<option value='0'>Select Division</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;


                            $('select[id$=divisrch1]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=divisrch1]').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: "assignspackagesstud.aspx/PopulateDropDownListCaste",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlcaste4]').empty();
                    $('select[id$=ddlcaste4]').append("<option value='0'>Select Caste</option>");
                    $.each(result.d, function (key, value) {
                        var dd = value.DeptName;


                        $('select[id$=ddlcaste4]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                        //console.log(value.DeptName);
                    });
                    $('select[id$=ddlcaste4]').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$=ddlcaste4]").change(function () {
                var obj = {};
                obj.yrs1 = $("select[id$=ddlyears3]").val();
                obj.castes = $("select[id$=ddlcaste4]").val();
                obj.clsid = $("select[id$=clasrch1]").val();
                obj.divsid = $("select[id$=divisrch1]").val();
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "assignspackagesstud.aspx/PopulateDropDownListstudent",
                    data: JSON.stringify(obj),
                    dataType: "json",
                    success: function (result) {
                        $('select[id$=ddlstudents]').empty();
                        $('select[id$=ddlstudents]').append("<option value='0'>Select Student</option>");
                        $.each(result.d, function (key, value) {
                            var dd = value.DeptName;
                            var fullnm = value.ptitle + "." + value.fname + " " + value.mname + " " + value.lname;

                            $('select[id$=ddlstudents]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(dd).html(fullnm));
                            //console.log(value.DeptName);
                        });
                        $('select[id$=ddlstudents]').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);
                    }

                });
            });
        });
        var markup = "";
        function getdata13() {
          
            $.ajax({
                type: "POST",
                url: "assignspackagesstud.aspx/GetDataUpdate",
                contentType: "application/JSON; charset=utf-8",
                data : "{studids : '"+ $("select[id$=ddlstudents]").val() +"' }",
                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++) {
                        var fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        table.row.add([
                             data[i].studid, fullname, data[i].clsname, data[i].divsname,
                             "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=editdata('" + data[i].packageid + "',\"" + data[i].studid + "\",'" + data[i].admyears + "','" + data[i].classd + "','" + data[i].divisionname + "') id='btnedit' class='btn btn-success' data-bs-toggle='modal' data-bs-target='#exampleLargeModal6' ><i class='bx bx-message-square-edit'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=deletedata('" + data[i].packageid + "',\"" + data[i].studid + "\",'" + data[i].admyears + "','" + data[i].classd + "','" + data[i].divsid + "') id='btndelete' class='btn btn-danger'><i class='fadeIn animated bx bx-trash-alt'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' class='btn btn-primary'><i class='lni lni-save'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' class='btn btn-dark'><i class='bx bx-x'></i></span></button>"

                        ]).draw(true);

                    }
                }
            });
        }
        function datatable() {
        
            $.ajax({
                type: "POST",
                url: "assignspackagesstud.aspx/GetDataUpdate1",
                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++) {
                        var fullname = data[i].title + "." + data[i].fname + " " + data[i].mname + " " + data[i].lname;
                        table.row.add([
                             data[i].studid, fullname, data[i].clsname,  data[i].divsname,
                             "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=editdata('" + data[i].packageid + "',\"" + data[i].studid + "\",'" + data[i].admyears + "','" + data[i].classd + "','" + data[i].divisionname + "') id='btnedit' class='btn btn-success' data-bs-toggle='modal' data-bs-target='#exampleLargeModal6' ><i class='bx bx-message-square-edit'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;display:none;' type='button' onclick=deletedata('" + data[i].packageid + "') id='btndelete' class='btn btn-danger'><i class='fadeIn animated bx bx-trash-alt'></i></button>"

                        ]).draw(true);

                    }
                }
            });
        }
        function editdata(pkgid, studid, yrsid, clsid, divsid) {
          
            studcode = studid;
            pkgcode = pkgid;
            admissionsyrs = yrsid;
            clsnm = clsid;
            divsnm = divsid;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "assignspackagesstud.aspx/PopulateDropDownListstudent1",
                data: "{studids : '" + studid + "',packagesid : '"+ pkgid +"'}",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddstud]').empty();
                    $('select[id$=ddstud]').append("<option value='0'>Select Student</option>");
                    $.each(result.d, function (key, value) {
                        var dd = value.DeptName;
                        var fullnm = value.ptitle + "." + value.fname + " " + value.mname + " " + value.lname;

                        $('select[id$=ddstud]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(dd).html(fullnm));
                        //console.log(value.DeptName);
                    });
                  //  $('select[id$=ddstud]').val('0').change();
                    $('select[id$=ddstud] option:eq(1)').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: "assignspackagesstud.aspx/PopulateDropDownList8",
                data: "",
                dataType: "json",
                success: function (result) {
                    $('select[id$=ddlpkg]').empty();
                    $('select[id$=ddlpkg]').append("<option value='0'>Select Package</option>");
                    $.each(result.d, function (key, value) {
                        var dd = value.DeptName;
                     
                        $('select[id$=ddlpkg]').append($("<option data-toggle='tooltip' data-placement='top' title='" + dd + "'></option>").val(value.DeptId).html(dd));
                        //console.log(value.DeptName);
                    });
                   $('select[id$=ddlpkg]').val(pkgid).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);
                }

            });
        }
      
            function updatepkg1() {

                if ($('select[id$=ddlpkg]').val() == "0") {
                    noty({ text: 'Please Select Package', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);
                    return false;
                }
               
             
                $.ajax({
                    url: 'assignspackagesstud.aspx/updatestudetails',
                    method: 'post',
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    data: "{ studidsids :'" + studcode + "',yrid :'"+ admissionsyrs +"',classids :'" + clsnm + "',divsid :'" + divsnm + "',pkgid:'" + $('select[id$=ddlpkg]').val() + "',pkgoldid :'" + pkgcode + "'}",
                    success: function (data) {
                        console.log(data.d);
                        noty({ text: 'Update Successfully', layout: 'topRight', type: 'information' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                        $("#Button1")[0].click();
                    },
                    error: function () {
                        noty({ text: 'Get Error', layout: 'topRight', type: 'error' });
                        setTimeout(function () { $.noty.closeAll(); }, 3000);
                    }

                });
            }
            function clears() {
            $("select[id$=ddlyears3]").val("0").change();
               $("select[id$=ddlcaste4]").val("0").change();
               $("select[id$=clasrch1]").val("0").change();
                $("select[id$=divisrch1]").val("0").change();
            }
    </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>Assign package List Student</h6>
						</div>
						<hr/>
                        <form class="row g-2">
                        <div class="col-md-2">
						
							<select class="form-select mb-3" id="ddlyears3" aria-label="Default select example">
						
							</select>
						</div>
						
                        <div class="col-md-2">
						
							<select class="form-select mb-3" id="clasrch1" aria-label="Default select example">
						
							</select>
						</div>
						
						
						<div class="col-md-2">
						
								<select class="form-select mb-3" id="divisrch1" aria-label="Default select example">
						
						
							</select>
						</div>  
                         <div class="col-md-2">
						
								<select class="form-select mb-3" id="ddlcaste4" aria-label="Default select example">
						
						
							</select>
						</div>
                        	<div class="col-md-2">
						
								<select class="form-select mb-3" id="ddlstudents" aria-label="Default select example">
						
						
							</select>
						</div>
                       
                       
                         <div class="col-md-1" style="margin-top: 1vh;">
						<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">
								<table class="table mb-0" id="Table1">
									<thead class="table-dark">
										<tr>
											
												
											<th scope="col">Stud ID</th>
											<th scope="col">Student Name</th>
											<th scope="col">Class</th>
											<th scope="col">Division</th>
                                            <th scope="col">Action</th>
										</tr>
									</thead>
									<tbody>
										
									
									</tbody>
								</table>
							</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>