Object
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace ClassObjects
{
[DataContract]
public class Class1
{
private string _id;
private string _Name;
private string _Age;
private string _Address;
private string _EmailId;
[DataMember]
public string id
{
get { return _id; }
set { _id = value; }
}
[DataMember]
public string EmailId
{
get { return _EmailId; }
set { _EmailId = value; }
}
[DataMember]
public string Address
{
get { return _Address; }
set { _Address = value; }
}
[DataMember]
public string Age
{
get { return _Age; }
set { _Age = value; }
}
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
//public static double NoOfDaysBefore = 30;
//public static double NoOfDaysAfter = 30;
//static BasicHttpBinding binding = null;
//public static BasicHttpBinding GetBinding()
//{
// binding = new BasicHttpBinding();
// binding.MaxReceivedMessageSize = 2147483647;
// binding.MaxBufferSize = 2147483647;
// binding.Security.Mode = BasicHttpSecurityMode.None;
// return binding;
//}
//public static string GetServicePath(string ServicePath, string ServiceName)
//{
// return (ServicePath + ServiceName);
//}
//public enum RequestType
//{
// NewUserRequest = 1
//}
}
}
DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using ClassObjects;
namespace Domain.DAL
{
public class ClassDal
{
public string create(Class1 obj)
{
string Name = string.Empty;
//string str = "Suresh";
//string Age = "21";
//string add = "Chennai";
//string email = "Gamil";
SqlConnection con = new SqlConnection("Data Source=Server1;Initial Catalog=freshers;User Id=vibrant;Pwd=vib");
con.Open();
SqlCommand cmd = new SqlCommand("sp_student", con);
{
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.Add(new SqlParameter("IsSave", true));
//cmd.Parameters.Add(new SqlParameter("id", DBNull.Value));
cmd.Parameters.Add(new SqlParameter("Name", obj.Name));
cmd.Parameters.Add(new SqlParameter("Age", obj.Age));
cmd.Parameters.Add(new SqlParameter("Address", obj.Address));
cmd.Parameters.Add(new SqlParameter("Emailid", obj.EmailId));
cmd.ExecuteNonQuery();
}
return Name;
}
public List<Class1> display()
{
List<Class1> Classlist = new List<Class1>();
Class1 objclass = null;
SqlDataReader reader = null;
SqlConnection con = new SqlConnection("Data Source=Server1;Initial Catalog=Freshers;User Id=vibrant;Pwd=vib");
con.Open();
SqlCommand cmd = new SqlCommand("griddisplay", con);
{
cmd.CommandType = CommandType.StoredProcedure;
reader = cmd.ExecuteReader();
while (reader.Read())
{
objclass = new Class1();
objclass.id = Convert.ToString(reader["id"]);
objclass.Name = Convert.ToString(reader["Name"]);
objclass.Age = Convert.ToString(reader["Age"]);
objclass.Address = Convert.ToString(reader["Address"]);
objclass.EmailId = Convert.ToString(reader["Emailid"]);
Classlist.Add(objclass);
}
reader.Close();
return Classlist;
}
}
}
}
BAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassObjects;
using Domain.DAL;
namespace Domain.BAL
{
public class ClassBal
{
public string create(Class1 bobj)
{
ClassDal objdal = new ClassDal();
return objdal.create(bobj);
}
public List<Class1> display()
{
ClassDal objdal = new ClassDal();
return objdal.display();
}
}
}
Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ClassObjects;
using Domain.BAL;
namespace Service
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public string create(Class1 bobj)
{
ClassBal objbal = new ClassBal();
return objbal.create(bobj);
}
public List<Class1> display()
{
ClassBal objdal = new ClassBal();
return objdal.display();
}
}
}
IService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ClassObjects;
using Domain.BAL;
namespace Service
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string create(Class1 bobj);
[OperationContract]
List<Class1> display();
}
}
Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication3.ServiceReference1;
using System.ServiceModel;
using Lib.Web.Mvc.JQuery.JqGrid;
using System.Text;
namespace MvcApplication3.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
//public ActionResult Index()
//{
// return View();
//}
public ActionResult Insert()
{
Service1Client objclient = new Service1Client();
return View();
}
public string create(string Name, string Age, string Address, string EmailId)
{
Class1 obj = new Class1();
//obj.id = id;
obj.Name = Name;
obj.Age = Age;
obj.Address = Address;
obj.EmailId = EmailId;
Service1Client objcreate = new Service1Client();
return objcreate.create(obj);
}
public ActionResult Griddisp()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Products(JqGridRequest request, Class1 viewModel)
{
Service1Client obj = new Service1Client();
JqGridResponse response = new JqGridResponse();
List<Class1> listobj = new List<Class1>();
var m = obj.display();
listobj = m.ToList();
foreach (Class1 product in listobj)
{
response.Records.Add(new JqGridRecord(Convert.ToString(product.id), new List<object>()
{
product.id,
product.Name,
product.Age,
product.Address,
product.EmailId,
}));
}
return new JqGridJsonResult() { Data = response };
}
}
}
Griddisp
@model MvcApplication3.ServiceReference1.Class1
@{
}
<!DOCTYPE html>
<html>
<head>
<title>create</title>
</head>
<body>
<div>
<input type="button" id="btnAddnew" value="AddNew" class="button" />
</div>
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.multiselect.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.tmpl.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.locale-en-4.1.2.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.jqGrid-4.1.2.min.js")" type="text/javascript"></script>
<link href="../../Content/themes/jquery-ui-jqgrid.css" rel="stylesheet" type="text/css" />
<link href="../../Content/themes/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="../../Content/themes/site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/themes/jquery-ui.multiselect.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#btnAddnew").click(function () {
window.location.href = '/Home/Insert';
});
$('#jqgProducts').jqGrid({
//url from wich data should be requested
url: '@Url.Action("Products")',
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
onSelectRow: function (DepartmentID) {
//trigger inline edit for row
$.post('@Url.Action("UpdateProduct")', { supplierId: DepartmentID }, function () {
});
},
//columns names
colNames: ['Id','Name', 'Age', 'Address', 'Emailid'],
//columns model
colModel: [
{ name: 'id', index: 'id', align: 'center' },
{name: 'Name', index: 'Name', align: 'center' },
{ name: 'Age', index: 'Age', align: 'center' },
{ name: 'Address', index: 'Address', align: 'center' },
{ name: 'Emailid', index: 'Emailid', align: 'center' },
],
//pager for grid
pager: $('#jqgpProducts'),
//number of rows per page
rowNum: 14,
//initial sorting column
sortname: 'Id',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//grid height
height: '100%'
});
$('#jqgProducts').jqGrid('navGrid', '#jqgpProducts',
{ add: false, del: true, edit: false, search: false },
{ width: 'auto', url: '@Url.Action("UpdateProduct")' },
{ width: 'auto', url: '@Url.Action("InsertProduct")' },
{ width: 'auto', url: '@Url.Action("DeleteProduct")' });
$('#jqgProducts').jqGrid('navGrid', '#jqgpProducts',
{ edit: false, add: false, del: true, search: false }, { width: 'auto', url: '@Url.Action("DeleteProduct")' }).jqGrid('navButtonAdd', '#jqgpProducts',
{
caption: 'Search',
buttonicon: 'ui-icon-search',
onClickButton: function () {
$('#jqgProducts').jqGrid('searchGrid', { multipleSearch: true });
},
position: 'last',
title: 'Search'
});
});
</script>
<table id="jqgProducts" cellpadding="0" cellspacing="0"></table>
<div id="jqgpProducts" style="text-align:center;"></div>
<div id="dlgSupplier"></div>
</body>
</html>
Insert
@model MvcApplication3.ServiceReference1.Class1
@{
}
<!DOCTYPE html>
<html>
<head>
<title>create</title>
</head>
<body>
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.multiselect.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.tmpl.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.locale-en-4.1.2.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.jqGrid-4.1.2.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnSave").click(function () {
var name = $('#txtName').val();
var age = $('#txtAge').val();
var address = $('#txtAddress').val();
var emailid = $('#txtEmail').val();
if (name == "") {
alert("Enter Name");
$('#txtName').focus();
return false;
}
else if (age == "") {
alert("Enter Age");
$('#txtAge').focus();
return false;
}
else if (address == "") {
alert("Enter Address");
$('#txtAddress').focus();
return false;
}
else if (emailid == "") {
alert("Enter Address");
$('#txtEmail').focus();
return false;
}
$.ajax({
url: '/Home/create',
Type: "POST",
data: { Name: name, Age: age, Address: address, EmailId: emailid },
success: function (data) {
alert('Record Save Successfully', window.location.href = '/Home/Griddisp')
}
});
// window.location.href = '/grid/Griddisp';
});
$("#btnClear").click(function () {
$('#txtName').val('');
$('#txtAge').val('');
$('#txtAddress').val('');
$('#txtEmail').val('');
});
});
</script>
<h2>Insert</h2>
<table>
<tr>
<td>Name :</td>
<td><input type="text" id="txtName" /></td>
</tr>
<tr>
<td>Age :</td>
<td><input type="text" id="txtAge" /></td>
</tr>
<tr>
<td>Address :</td>
<td><input type="text" id="txtAddress" /></td>
</tr>
<tr>
<td>EmailId :</td>
<td><input type="text" id="txtEmail" /></td>
</tr>
</table>
<table>
<tr>
<td><input type="submit" value="Save" id="btnSave" class="button" /></td>
@* <td><input type="submit" value="Update" id="btnUpdate" class="button" /></td>
<td><input type="submit" value="Delete" id="btnDelete" class="button" /></td>*@
<td><input type="submit" value="Clear" id="btnClear" class="button" /></td>
</tr>
</table>
</body>
</html>