Asked by:
in this code web services and jquery .how to convert 3 tier archtiatare in asp.net

Question
-
User1665719730 posted
public void Admin_GetUsersWithSearch(string AssessmentDate,int SectorId,int JobRoleId, string SDMSId, int PageIndex)
{
int PageSize = 5;
int RecordCount = 0;
List<masters> listbatchdetails = new List<masters>();
using (SqlConnection con = new SqlConnection(strConn))
{
SqlCommand cmd = new SqlCommand("Admin_GetUsersWithSearch", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AssessmentDate", AssessmentDate);
cmd.Parameters.AddWithValue("@SectorId", SectorId);
cmd.Parameters.AddWithValue("@JobRoleId", JobRoleId);
cmd.Parameters.AddWithValue("@SDMSId", SDMSId);
cmd.Parameters.AddWithValue("@PageIndex", PageIndex);
cmd.Parameters.AddWithValue("@PageSize", PageSize);
cmd.Parameters.AddWithValue("@RecordCount", RecordCount);
cmd.Parameters.AddWithValue("@ClientId", HttpContext.Current.Session["ClientId"].ToString());
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
masters objbatch = new masters();if (dr["BatchId"] != null && dr["BatchId"] != DBNull.Value)
{
objbatch.BatchId = int.Parse(dr["BatchId"].ToString());
}
else
{
objbatch.BatchId = 0;
}
objbatch.SDMSId = dr["SDMSId"].ToString();
objbatch.SectorName = dr["SectorName"].ToString();
objbatch.JobRoleName = dr["JobRoleName"].ToString();
objbatch.State = dr["State"].ToString();
objbatch.City = dr["City"].ToString();
objbatch.AssessmentStartDate = dr["AssessmentStartDate"].ToString();
listbatchdetails.Add(objbatch);
}
cmd.Dispose();
con.Close();
con.Dispose(); webservice code
}------------------------------------------------------<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="download_users.aspx.cs" Inherits="download_users" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="row">
<div class="col-md-12 connectedSortable ui-sortable">
<section class="content-header">
<h1>Download Candidates</h1>
<ol class="breadcrumb">
<li><a href="dashboard.aspx"><i class="fa fa-dashboard"></i>Candidate</a></li>
<li class="active">Download</li>
</ol>
</section>
<section class="content fill-profile">
<div class="row">
<div class="col-md-12" runat="server" id="mypnl" visible="true">
<div class="box box-danger">
<%--<div class="box-header with-border">
<span class="box-title">Download Users</span> <a href="javascript:history.back();" class="pull-right"><i class="fa fa-arrow-left" aria-hidden="true"></i>Back</a>
</div>--%>
<div class="box-body">
<div class="row" style="margin-bottom: 30px;">
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-building-o"></i></span>
<select id="ddl_Sector" runat="server" class="form-control">
</select>
</div>
</div>
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-building-o"></i></span>
<select id="ddl_JobRoleName" runat="server" class ="form-control">
</select>
</div>
</div>
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<asp:TextBox ID="txt_AssessmentDate" runat="server" CssClass="form-control" placeholder="Search By Assessment Date" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="MM/dd/yyyy" TargetControlID="txt_AssessmentDate"></asp:CalendarExtender>
</div>
</div>
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<asp:TextBox ID="txt_SDMSId" runat="server" CssClass="form-control" placeholder="Search By SDMSId" />
</div>
</div>
</div>
<%--<asp:GridView ID="gv_Batches" runat="server" DataKeyNames="SDMSID,Batchid" AutoGenerateColumns="False" ShowHeaderWhenEmpty="true">
<Columns>
<asp:TemplateField HeaderText="Sno" HeaderStyle-BackColor="#f1f1f1">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SDMSID" HeaderText="SDMSID" SortExpression="SDMSID" HeaderStyle-BackColor="#f1f1f1"></asp:BoundField>
<asp:BoundField DataField="JobRoleName" HeaderText="Test Type" SortExpression="TestName" HeaderStyle-BackColor="#f1f1f1"></asp:BoundField>
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" HeaderStyle-BackColor="#f1f1f1"></asp:BoundField>
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" HeaderStyle-BackColor="#f1f1f1"></asp:BoundField>
<asp:BoundField DataField="AssessmentStartDate" HeaderText="Assessment StartDate" DataFormatString="{0:d}" SortExpression="AssessmentStartDate" HeaderStyle-BackColor="#f1f1f1"></asp:BoundField></Columns>
<EmptyDataTemplate>
<center>
<asp:Label ID="Label1" runat="server" Text="No data available !" ForeColor="Red"></asp:Label></center>
</EmptyDataTemplate>
</asp:GridView>--%>
<table id="gv_Batches" class="table table-bordered table-striped dataTable">
<thead>
<tr>
<th>BatchId</th>
<th>SDMSID</th>
<th>SectorName</th>
<th>JobRoleName</th>
<th>State</th>
<th>City</th>
<th>AssessmentStartDate</th>
<th>Download Candidates</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<%-- <div class="Pagination" style="background-color: orange; font-family: Verdana; font-size: 10pt; height: 30px; text-align: center; vertical-align: central; padding-top: 20px; padding-bottom: 10px;">
</div>--%>
<!-- /input-group -->
</div>
<!-- /.box-body -->
</div>
</div>
</div>
</section>
<!-- /.content -->
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress2" DisplayAfter="0" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="modal1" style="; top: 30%; z-index: 999; left: 40%;">
<div class="center">
<img alt="" src="img/gears.gif" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress><script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$("#gv_Batches").on('click', 'td', function () {
alert($(this).text());
var str = $(this).text();
//location.href = "/view_users_ststus.aspx?strReq=" + str;
});
$(document).ready(function () {
var SectorDDL = $("#<%=ddl_Sector.ClientID%>");
var JobroleDDL = $("#<%=ddl_JobRoleName.ClientID%>");$.ajax({
url: 'Getdropdowns.asmx/GetSectors1',
method: 'post',
dataType: 'json',
success: function (data) {
SectorDDL.append($('<option/>', { value: 0, text: 'Select Sector' }));
JobroleDDL.append($('<option/>', { value: 0, text: 'Select Jobrole' }));
JobroleDDL.prop('disabled', true);$(data).each(function (index, item) {
SectorDDL.append($('<option/>', { value: item.SectorId, text: item.SectorName }));
});
},
error: function (err) {
alert(err);
}
});SectorDDL.change(function () {
if ($(this).val() == "0") {
JobroleDDL.empty();
JobroleDDL.append($('<option/>', { value: 0, text: 'Select Jobrole' }));
JobroleDDL.val('0');
JobroleDDL.prop('disabled', true);
}
else {
$.ajax({
url: 'Getdropdowns.asmx/GetJobroleBySectorId',
method: 'post',
dataType: 'json',
data: { SectorId: $(this).val() },
success: function (data) {
JobroleDDL.empty();
JobroleDDL.append($('<option/>', { value: 0, text: 'Select Jobrole' }));
$(data).each(function (index, item) {
JobroleDDL.append($('<option/>', { value: item.JobRoleId, text: item.JobRoleName }));
});
JobroleDDL.val('0');
JobroleDDL.prop('disabled', false);
},
error: function (err) {
alert(err);
}
});
}
});Bindgrid();
$("#<%=ddl_Sector.ClientID%>").change(function () {
$('#gv_Batches').empty();
Bindgrid();
});
$("#<%=ddl_JobRoleName.ClientID%>").change(function () {
$('#gv_Batches').empty();
Bindgrid();
});
$("#<%=txt_AssessmentDate.ClientID%>").change(function () {
$('#gv_Batches').empty();
Bindgrid();
});
$("#<%=txt_SDMSId.ClientID%>").keyup(function () {
$('#gv_Batches').empty();
Bindgrid();
});
});
</script>
<script type="text/javascript">
function Bindgrid() {
var Assessment_Date = $("#<%=txt_AssessmentDate.ClientID%>").val();
if (Assessment_Date.length == 0) {
Assessment_Date = "1/1/1900 12:00:00";
}
var Sector_Id = $("#<%=ddl_Sector.ClientID%>").val();
if (Sector_Id == null || Sector_Id == "") {
Sector_Id = 0;
}
var JobRole_Id = $("#<%=ddl_JobRoleName.ClientID%>").val();
if (JobRole_Id == null || JobRole_Id == "") {
JobRole_Id = 0;
}
var SDMS_Id = $("#<%=txt_SDMSId.ClientID%>").val();
var page_Index = 1;
$.ajax({
url: 'Getdropdowns.asmx/Admin_GetUsersWithSearch',
method: 'post',
dataType: 'json',
data: {
AssessmentDate: Assessment_Date,
SectorId: Sector_Id,
JobRoleId: JobRole_Id,
SDMSId: SDMS_Id,
PageIndex: page_Index
},
success: function (data) {
$('#gv_Batches').dataTable({
paging: false,
sort: true,
searching: false,
processing: true,
destroy: true,
data: data,
columns: [
{ 'data': 'BatchId' },
{ 'data': 'SDMSId' },
{ 'data': 'SectorName' },
{ 'data': 'JobRoleName' },
{ 'data': 'State' },
{ 'data': 'City' },
{
'data': 'AssessmentStartDate',
'render': function (Assessment_Date) {
var date = new Date(Assessment_Date);
var month = date.getMonth() + 1;
return (month.length > 1 ? month : "0" + month) + "/" + date.getDate() + "/" + date.getFullYear();
}
},
{
'data': 'BatchId',
'render': function (BatchId) {
var encodedUrl = encodeURIComponent(BatchId);
return '<a href=user_details_edit.aspx?dmFsdWUxfHZhbHVlMnx2YWx1ZTM=' + encodedUrl + '>Download Candidates</a>';
}
}
]
});
}
});
}</script>
</asp:Content>-------------------------------------jquery code
Thursday, October 11, 2018 11:00 AM
All replies
-
User475983607 posted
The unformatted code dumped on the forum look like Web Forms and some AJAX. Can you clarify the problem you are trying to solve?
Thursday, October 11, 2018 11:17 AM -
User61956409 posted
Hi nagaraji,
Normally, we have three layers: Application Layer or Presentation Layer (web form and UI part), Business Logic Layer (BLL) and Data Access Layer (DAL) in three tier architecture.
Based on your code structure and style, you are using ASP.NET webform and implement code logic in code behind (.aspx.cs), and you are using ADO.NET technology to access&operate your database. If you want to modify your application in three tier architecture, you can create DAL.cs class to connect to and access database, and then write the business logic (consume DAL's methods) in BLL.cs class.
This article explain how to create three-tier architecture for projects in Asp.net, please refer to it.
Note: if your project is not a large project, using three tier architecture might consume more time than using 2-Tier architecture.
With Regards,
Fei Han
Friday, October 12, 2018 5:55 AM