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

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
        $(document).ready(function () {
            datatable(); $("#btnadd").show();
        });
        function datatable() {
            $.ajax({
                type: "POST",
                url: "incomemaster.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, count = 1; i < data.length; i++, count++) {
                        table.row.add([
                             count, data[i].incomes, data[i].shortscodes, data[i].statuss,
                             "<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;display:none' type='button' class='btn btn-primary'><i class='lni lni-save'></i></button> <button  style='height:35px; width: 35px; padding-left:7px;display:none' type='button' class='btn btn-dark'><i class='bx bx-x'></i></span></button>"

                        ]).draw(true);

                    }
                }
            });
        }
        var id1 = "";
        function editdata(id) {
            $("#btnadd").hide(); $("#Button1").show();
            $.ajax({

                url: "incomemaster.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);
                    $("#txtname").val(data[0].incomes);
                    $('select[id$=ddlsemister]').val(data[0].statuss).change();
                    $("#txtcode").val(data[0].shortscodes);
                    id1 = id;

                    datatable();
                   

                }
            });
        }
        function Savedata() {
            var obj = {};
            obj.inname = $("#txtname").val();
            obj.scode = $("#txtcode").val();
            obj.sts = $("select[id$=ddlsemister]").val();
            $.ajax({
                type: "POST",
                url: "incomemaster.aspx/SavaData",
                data: JSON.stringify(obj),
                contentType: "application/JSON; charset=utf-8",
                datatype: "JSON",
                success: function (response) {
                    //window.location.reload();
                    $("#txtname").val(""); $("#txtcode").val(""); $("select[id$=ddlsemister]").val("").change();
                    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);

                }

            });
        }
        function Updatedata() {
            var obj = {};
            obj.incid = id1;
            obj.inname = $("#txtname").val();
            obj.scode = $("#txtcode").val();
            obj.sts = $("select[id$=ddlsemister]").val();
            $.ajax({

                url: "incomemaster.aspx/UpdateData",
                contentType: "application/JSON; charset=utf-8",
                method: "post",
                datatype: "JSON",
                data: JSON.stringify(obj),
                success: function (data) {
  noty({ text: 'Update Successfully', layout: 'topRight', type: 'information' });
                    setTimeout(function () { $.noty.closeAll(); }, 3000);

                    datatable();
                    $("#btnadd").show(); $("#Button1").hide();
                    $("#txtname").val("");
                    $('select[id$=ddlsemister]').val("0").change();
                    $("#txtcode").val("");
                 
                  
                }
            });
        }
        function deletedata(id1) {

            $.ajax({

                url: "incomemaster.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>
  	<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>Incomes</h6>
						</div>
						<hr />
                        	<form class="row g-2">
							<div class="col-md-12"></div>
                              <div class="col-md-3">
								<label style="font-weight:bold">Income</label>
							<input type="text" class="form-control" id="txtname" />
							</div>
                                  <div class="col-md-3">
								<label style="font-weight:bold">Short Code</label>
							<input type="text" class="form-control" id="txtcode" />
							</div> 
                                   <div class="col-md-3">
								<label style="font-weight:bold">Status</label>
					
								<select id="ddlsemister" class="form-select">
                                    <option value="">Select Status</option>
                                    <option value="Active">Active</option>		
                                      <option value="InActive">InActive</option>						
								</select>
							</div>
                                <div class="col-md-2" style="margin-top: 4.7vh;">
			        <button type="button" id="btnadd" value="Submit" onclick="Savedata();" class="btn btn-primary" style="display:none"><i class='bx bx-plus-circle'></i>Add</button>  <button type="button" id="Button1" value="Submit" onclick="Updatedata();" class="btn btn-primary" style="display:none"><i class='bx bx-plus-circle'></i>Update</button>
							
											
						   </div>
                                </form>
							</div>
                              
                        </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" style="text-align:center">
								   <thead>
									   <tr>
										   <th>Sr.no</th>	
                                            <th>Income</th>
										 
										   	 <th>Short Code</th>  
                                            <th>Status</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>
                    </div>
                </div>
        
    </asp:Content>