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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <script src="../assets/js/jquery.min.js"></script>
   <script type="text/javascript">

       $(document).ready(function () {
           $("#btnadd").click(function () {
               //btnadd();
               if ($("#btnadd").val() == "Submit") {
                   btnadd();
               }
               else if ($("#btnadd").val() == "Update") {
                   updatedata();
               }
           });
           datatable();
       });

       function btnadd() {
           if ($("#feename").val() != "") {

               $.ajax({
                   type: "POST",
                   url: "Feecategory.aspx/SavaData",
                   data: "{ feesname:'" + $("#feename").val() + "'}",
                   contentType: "application/JSON; charset=utf-8",
                   datatype: "JSON",
                   success: function (response) {
                       //window.location.reload();
                       $("#feename").val("");
                       datatable();
                       noty({ text: 'Insert Successfully', layout: 'topRight', type: 'information' });
                       setTimeout(function () { $.noty.closeAll(); }, 3000);
                   },
                   error: function (error) {
                       console.log(JSON.stringify(error));
                       //alert("Error in insert");
                       noty({ text: 'Error in insert', layout: 'topRight', type: 'information' });
                       setTimeout(function () { $.noty.closeAll(); }, 3000);

                   }

               });
           }
           else {
               noty({ text: 'Please Enter Fee Name', layout: 'topRight', type: 'information' });
               setTimeout(function () { $.noty.closeAll(); }, 3000);
           }
       }

       var id1 = "";
       function editdata(id) {
           $.ajax({

               url: "Feecategory.aspx/EditData",
               contentType: "application/JSON; charset=utf-8",
               method: "post",
               datatype: "JSON",
               data: "{id:'" + id + "'}",
               success: function (data) {
                   data = JSON.parse(data.d);
                   console.log(data);
                   $("#feename").val(data[0].feesname);

                   id1 = id;

                   datatable();
                   $("#btnadd").val('Update');

               }
           });
       }

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

               datatype: "JSON",
               success: function (data) {
                   var table = $('#dataemp').DataTable();
                   data = JSON.parse(data.d);
                   table.clear();
                   for (var i = 0; i < data.length; i++) {
                       table.row.add([
                            data[i].id, data[i].feesname,
                            "<button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=editdata('" + data[i].id + "') id='btnedit' class='btn btn-success'  ><i class='bx bx-message-square-edit'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;' type='button' onclick=deletedata('" + data[i].id + "') 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 updatedata() {

           $.ajax({

               url: "Feecategory.aspx/UpdateData",
               contentType: "application/JSON; charset=utf-8",
               method: "post",
               datatype: "JSON",
               data: "{id:'" + id1 + "',feesname:'" + $("#feename").val() + "' }",
               success: function (data) {


                   datatable();

                   $("#feename").val("");

                   $("#btnadd").val("Update");
                   noty({ text: 'Update Successfully', layout: 'topRight', type: 'information' });
                   setTimeout(function () { $.noty.closeAll(); }, 3000);
               }
           });
       }
       function deletedata(id1) {

           $.ajax({

               url: "Feecategory.aspx/DeleteData",
               contentType: "application/JSON; charset=utf-8",
               method: "post",
               datatype: "JSON",
               data: "{id:'" + id1 + "'}",
               success: function (data) {
                   datatable();
                   noty({ text: 'Delete Successfully', layout: 'topRight', type: 'information' });
                   setTimeout(function () { $.noty.closeAll(); }, 3000);

               }
           });
       }
   </script>

    <!--start page wrapper -->
		<div class="page-wrapper">
			<div class="page-content">
				<div class="row">
					<div class="col-md-8 mx-auto" >
					
				<div class="card">
					<div class="card-body">
						<div class="card-title d-flex align-items-center">

							<h6>Fee Category</h6>
						</div>
						<hr>
						
						
						<form class="row g-2">
							<div class="col-md-2"></div>
							<div class="col-md-3">
								<label>Fee Name</label>
								<input class="form-control mb-3" type="text" id="feename" placeholder="Fee Name"
								aria-label="default input example">
							</div>
					<div class="col-md-2" style="margin-top: 4.7vh;">
			        <button type="button" id="btnadd" value="Submit" class="btn btn-primary"><i class='bx bx-plus-circle'></i>Add</button>
							
											
						   </div>
						   
                           </form>
                       </div>
                   </div>
				

				   <div class="overlay toggle-icon"></div>
				   <hr/>
				   <div class="col-md-12 mx-auto">
				   <div class="card">
					   <div class="card-body">
						   <div class="table-responsive">
							   <table id="dataemp" class="table table-striped table-bordered">
								   <thead>
									   <tr>
										   <th>Sr.no</th>	
										   <th>Fee Name</th>
										   	   
										   <th style="background-color: white;">Action</th>
									   </tr>
								   </thead>
								   <%--<tbody>
									   <tr>
										   <td>1</td>
										   <td>Admission Fee</td>	
										   
										   <td style="background-color: white;">
																			
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-success"  ><i class='bx bx-message-square-edit'></i>
											</button>&nbsp;<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-danger"><i class="fadeIn animated bx bx-trash-alt"></i>
											</button>&nbsp;
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-primary"><i class="lni lni-save"></i>
											</button>&nbsp;
											<button  style="height:35px; width: 35px; padding-left:7px;" type="button" class="btn btn-dark"><i class='bx bx-x'></i></span>
											</button>
											</td>
										</div>	
										</div>		
										</div>								
										   </tr>
									   </tbody>--%>
							   </table>
						   </div>
					   </div>
				   </div>
			   </div>
			   </div>
</asp:Content>

