Calendar Scheduler:using DHXScheduler dll
Code In Controller:
public class CalendarController : Controller
{
Entities1 entity = new Entities1();
public ActionResult Index()
{
//Being initialized in that way, scheduler will use CalendarController.Data as a the datasource and CalendarController.Save to process changes
var scheduler = new DHXScheduler(this);
/*
* It's possible to use different actions of the current controller
* var scheduler = new DHXScheduler(this);
* scheduler.DataAction = "ActionName1";
* scheduler.SaveAction = "ActionName2";
*
* Or to specify full paths
* var scheduler = new DHXScheduler();
* scheduler.DataAction = Url.Action("Data", "Calendar");
* scheduler.SaveAction = Url.Action("Save", "Calendar");
*/
/*
* The default codebase folder is ~/Scripts/dhtmlxScheduler. It can be overriden:
* scheduler.Codebase = Url.Content("~/customCodebaseFolder");
*/
scheduler.InitialDate = new DateTime(2012, 09, 03);
scheduler.LoadData = true;
scheduler.EnableDataprocessor = true;
return View(scheduler);
}
public ContentResult Data()
{
var data = new SchedulerAjaxData(new eCRM_MastersEntities1().Events);
return (ContentResult)data;
}
public ContentResult Save(eCRM_Entity.Event updateevents, FormCollection actionValues)
{
var action = new DataAction(actionValues);
entity = new eCRM_MastersEntities1();
try
{
//var changedEvent = (Tbl_Calendar)DHXEventsHelper.Bind(typeof(Tbl_Calendar), actionValues);
switch (action.Type)
{
case DataActionTypes.Insert:
//do insert
entity.Events.Add(updateevents);
break;
case DataActionTypes.Delete:
//do delete
break;
default:// "update"
//do update
break;
}
entity.SaveChanges();
action.TargetId = updateevents.id;
}
catch
{
action.Type = DataActionTypes.Error;
}
return (ContentResult)new AjaxSaveResponse(action);
}
}
In Model:
using System;
using System.Collections.Generic;
public partial class Event
{
public int id { get; set; }
public string text { get; set; }
public System.DateTime start_date { get; set; }
public System.DateTime end_date { get; set; }
public Nullable<int> UserId { get; set; }
}
In View
@{
Layout = "~/Views/Shared/_UserLayout.cshtml";
ViewBag.Title = "Event Calender";
}
<h2 class="topHeader">
Events Details:</h2>
<br />
<div style="height:700px;width:900px;">
@Html.Raw(Model.Render())
</div>
Add DHXScheduler Dll :
Example :
.NET,MVC,MVC API,jQuery,SQL Server, Sql Business Intelligence,QlickView,Sharepoint,Sharepoint Performancepoint
Monday, August 26, 2013
Friday, August 2, 2013
Create Layout In MVC4
Create Layout In MVC4:
1.Create SideMenu With Header Page
2.Create SideMenu Page
3.Create Layout Page.
Layout Example Code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="../../Content/prefixfree-1.0.7.js" type="text/javascript"></script>
<link href="../../Content/Menu.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script src="../../Content/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Content/prefixfree-1.0.7.js" type="text/javascript"></script>
<link href="../../Content/sidemenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
<table style="width:100%;height:50%">
<tr >
<td style="width:45%;top:auto;margin-left:20%"> <img src="../../Content/Images/Untitled.png" /></td>
<td style="margin-left:32%;height:50%">@Html.Partial("Menu") </td>
</tr>
<tr></tr>
</table>
<table style="width:100%">
<tr valign="top">
<td style="width:15%;top:auto" valign="top"> @Html.Partial("Sidemenu")</td>
<td style="width:85%;background-color:White;height:600px;">
@RenderBody()
</td>
</tr>
</table>
<div style="height:100px;background-color:Yellow;">
</div>
</div>
</body>
</html>
My Layout Page:
Question How Call Page In Your Pages:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Your page title";
}
Hope It will help you.....enj
1.Create SideMenu With Header Page
2.Create SideMenu Page
3.Create Layout Page.
Layout Example Code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="../../Content/prefixfree-1.0.7.js" type="text/javascript"></script>
<link href="../../Content/Menu.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script src="../../Content/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Content/prefixfree-1.0.7.js" type="text/javascript"></script>
<link href="../../Content/sidemenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
<table style="width:100%;height:50%">
<tr >
<td style="width:45%;top:auto;margin-left:20%"> <img src="../../Content/Images/Untitled.png" /></td>
<td style="margin-left:32%;height:50%">@Html.Partial("Menu") </td>
</tr>
<tr></tr>
</table>
<table style="width:100%">
<tr valign="top">
<td style="width:15%;top:auto" valign="top"> @Html.Partial("Sidemenu")</td>
<td style="width:85%;background-color:White;height:600px;">
@RenderBody()
</td>
</tr>
</table>
<div style="height:100px;background-color:Yellow;">
</div>
</div>
</body>
</html>
My Layout Page:
Question How Call Page In Your Pages:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Your page title";
}
Hope It will help you.....enj
Dynamic Controls In MVC using Jquery
Dynamic Controls In MVC4 using Jquery:
View Code:
@using (Html.BeginForm("AddShippingLocation", "Location", "POST"))
{
<input type="hidden" id="hdncountryid" />;
<input type="hidden" id="hdnstateid" />;
<input type="hidden" id="hdncityeid" />;
<input type="hidden" id="hdnAddress1" />;
<input type="hidden" id="hdnAddress2" />;
<input type="hidden" id="hdnZipCode" />;
<input type="hidden" id="hdnPhone" />;
<input type="hidden" id="hdnExtension" />;
<input type="hidden" id="hdnFax" />;
eCRM.Controllers.eCRM_Masters.LocationController dp = new eCRM.Controllers.eCRM_Masters.LocationController();
eCRM_Entity.eCRM_MastersEntities1 entities = new eCRM_Entity.eCRM_MastersEntities1();
List<SelectListItem> list = new List<SelectListItem>();
list.Add(new SelectListItem { Text = "-Select Country-", Value = "Selects items" });
var cat = (from c in entities.tbl_Country select c).ToArray();
for (int i = 0; i < cat.Length; i++)
{
list.Add(new SelectListItem
{
Text = cat[i].CountryName,
Value = cat[i].CountryId.ToString(),
Selected = (cat[i].CountryId == 0)
});
}
ViewData["danhsach"] = list;
<div>
<legend>***********Shipping Address**********</legend>
</div>
<div id='AppSelectorGroup'>
<div id="AppSelectorBox_1" style="display: block; float: left;">
<div class="editor-field">
@Html.DropDownList("CountryId", (IEnumerable<SelectListItem>)ViewData["danhsach"],
new { @class = "CssCategory", id = "CountryId" })
@Html.DropDownList("State_Id", new SelectList("State_Id", "StateName"), new { @class = "CssSubcategory", id = "State_Id" })
@Html.DropDownList("CityId", new SelectList("CityId", "CityName"), new { @class = "CssSubcategorycity", id = "CityId" })
Address1
@Html.TextBox("Address1", null, new { id = "Address11" })
Address2
@Html.TextBox("Address2", null, new { id = "Address21" })
ZipCode
@Html.TextBox("ZipCode", null, new { id = "ZipCode1" })
Phone
@Html.TextBox("Phone", null, new { id = "Phone1" })
Extension
@Html.TextBox("Extension", null, new { id = "Extension1" })
Fax
@Html.TextBox("Fax", null, new { id = "Fax1", @class = "deleteAppselector" })
</div>
</div>
<div class="clear-fix"></div>
</div>
<p>
<input type="submit" value="Save" name="Command" id="btn1" />
<input type="submit" value="Cancel" name="Command" />
</p>
//Page Validation
<script type="text/javascript">
$("#btn1").click(function (e) {
debugger;
// e.preventDefault();
var CountryId = $('#CountryId option:selected').val();
var StateId = $('#State_Id option:selected').val();
var CityId = $('#CityId option:selected').val();
if (CountryId == 0) {
alert("Please select country.")
return false;
}
if (StateId == 0) {
alert("Please select State.")
return false;
}
if (CityId == 0) {
alert("Please select City.")
return false;
}
var address1 = $("#Address11").val();
if (address1 == '') {
alert("Please enter address1");
return false;
}
var Address21 = $("#Address21").val();
if (Address21 == '') {
alert("Please enter Address2");
return false;
}
var ZipCode1 = $("#ZipCode1").val();
if (ZipCode1 == '') {
alert("Please enter ZipCode");
return false;
}
var Phone1 = $("#Phone1").val();
if (Phone1 == '') {
alert("Please enter Phone");
return false;
}
var Extension1 = $("#Extension1").val();
if (Extension1 == '') {
alert("Please enter Extension");
return false;
}
var Fax1 = $("#Fax1").val();
if (Fax1 == '') {
alert("Please enter Fax");
return false;
}
///////////////////////////
var hdncountryid = $("#hdncountryid").val();
var CountryId2 = $(hdncountryid + ' option:selected').val();
var hdnstateid = $("#hdnstateid").val();
var StateId2 = $(hdnstateid + ' option:selected').val();
var hdncityeid = $("#hdncityeid").val();
var Cityid2 = $(hdncityeid + ' option:selected').val();
///////////////////////////////
// var CountryId = $('#CountryId option:selected').val();
// var StateId = $('#State_Id option:selected').val();
// var CityId = $('#CityId option:selected').val();
if (CountryId2 == 0) {
alert("Please select country.")
return false;
}
if (StateId2 == 0) {
alert("Please select State.")
return false;
}
if (Cityid2 == 0) {
alert("Please select City.")
return false;
}
var address11 = $("#hdnAddress1").val();
if (address11 == '') {
alert("Please enter address1");
return false;
}
var Address212 = $("#hdnAddress2").val();
if (Address212 == '') {
alert("Please enter Address2");
return false;
}
var ZipCode12 = $("#hdnZipCode").val();
if (ZipCode12 == '') {
alert("Please enter ZipCode");
return false;
}
var Phone11 = $("#hdnPhone").val();
if (Phone11 == '') {
alert("Please enter Phone");
return false;
}
var Extension11 = $("#hdnExtension").val();
if (Extension11 == '') {
alert("Please enter Extension");
return false;
}
var Fax11 = $("#hdnFax").val();
if (Fax11 == '') {
alert("Please enter Fax");
return false;
}
});
$('#CountryId').change(function () {
var CountryId = $(this).val();
var URLS1 = '@Url.Action("GetState")' + '?CountryId=' + CountryId;
$.getJSON(URLS1, function (dataS1) {
$('#State_Id').html(dataS1);
});
});
$('#State_Id').change(function () {
var StateId = $(this).val();
var URLC1 = '@Url.Action("GetCity")' + '?StateId=' + StateId;
$.getJSON(URLC1, function (dataC1) {
$('#CityId').html(dataC1);
});
});
//Dropdown Selection Change event...
function onSelectChangeCountry() {
var hdncountryid = $("#hdncountryid").val();
var CountryId = $(hdncountryid + ' option:selected').val();
var URLS1 = '@Url.Action("GetState")' + '?CountryId=' + CountryId;
$.getJSON(URLS1, function (dataS1) {
var hdnstateid = $("#hdnstateid").val();
$(hdnstateid).html(dataS1);
});
}
function onSelectChangeState() {
var hdnstateid = $("#hdnstateid").val();
var StateId = $(hdnstateid + ' option:selected').val();
var URLC1 = '@Url.Action("GetCity")' + '?StateId=' + StateId;
$.getJSON(URLC1, function (dataC1) {
var hdncityeid = $("#hdncityeid").val();
$(hdncityeid).html(dataC1);
});
}
</script>
//Dynamic Code ...For Genrate DropDownlist and Text Boxs//
<script type="text/javascript">
//Jquery for handling the Click Event and Creating the Dynamic Controls:
//----------Begin: For Creating App Selector Groups---------------//
var deleteAppSelectror = $(".deleteAppselector").length;
/* For Adding the Control */
$("#addAppSelector").click(function () {
debugger;
if (deleteAppSelectror == 10) {
$("#addAppSelector").hide();
$("#removeAppSelector").show();
//alert("Only 10 URLs are allowed");
return false;
}
else {
$("#addAppSelector").show();
$("#removeAppSelector").show();
}
deleteAppSelectror++;
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'AppSelectorBox__' + deleteAppSelectror);
var URL = '@Url.Action("Getcountry")';
newTextBoxDiv.append('<div class="editor-label"><label>Shipping Address: </label></div>' +
'<select name="CountryId" onChange="onSelectChangeCountry();" id="CountryId' + deleteAppSelectror + '" class="valid" style = "width:80px"> </select>'
+
' <select name="State_Id" onChange="onSelectChangeState();" id="State_Id' + deleteAppSelectror + '" class="valid" style = "width:80px"> </select>' +
' <select name="CityId" id="CityId' + deleteAppSelectror + '" class="valid" style = "width:80px"> </select>' +
'Address1<div class="editor-field"><input type="text" name="Address1" id="Address1' + deleteAppSelectror + '" value="" />' +
'Address2<input type="text" name="Address2" id="Address2' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'ZipCode<input type="text" name="ZipCode" id="ZipCode' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'Phone<input type="text" name="Phone" id="Phone' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'Extension<input type="text" name="Extension" id="Extension' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'Fax<input type="text" name="Fax" class="deleteAppselector" id="Fax' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'</div><div class="clear-fix"></div>');
$.getJSON(URL, function (data) {
var ddlcountry = '#CountryId' + deleteAppSelectror;
$(ddlcountry).html(data);
var ddlstate = '#State_Id' + deleteAppSelectror;
var ddlcity = '#CityId' + deleteAppSelectror;
$("#hdncountryid").val(ddlcountry);
$("#hdnstateid").val(ddlstate);
$("#hdncityeid").val(ddlcity);
var Address1 = '#Address1' + deleteAppSelectror;
var Address2 = '#Address2' + deleteAppSelectror;
var ZipCode = '#ZipCode' + deleteAppSelectror;
var Phone = '#Phone' + deleteAppSelectror;
var Extension = '#Extension' + deleteAppSelectror;
var Fax = '#Fax' + deleteAppSelectror;
$("#hdnAddress1").val(Address1);
$("#hdnAddress2").val(Address2);
$("#hdnZipCode").val(ZipCode);
$("#hdnPhone").val(Phone);
$("#hdnExtension").val(Extension);
$("#hdnFax").val(Fax);
})
newTextBoxDiv.appendTo("#AppSelectorGroup");
if (deleteAppSelectror == 10) {
$("#addAppSelector").hide();
$("#removeAppSelector").show();
return false;
}
return true;
});
/* For Removing the Control */
$("#removeAppSelector").click(function () {
debugger;
if (deleteAppSelectror == 1) {
$("#removeAppSelector").hide();
$("#addAppSelector").show();
return false;
}
else {
$("#removeAppSelector").show();
$("#addAppSelector").show();
}
$('.deleteAppselector').last().parent().parent().remove();
deleteAppSelectror--;
if (deleteAppSelectror == 1) {
$("#removeAppSelector").hide();
$("#addAppSelector").show();
return false;
}
return true;
});
//----------End: For Creating App Selector Groups---------------//
</script>
}
Hope it will help u...enj...
View Code:
@using (Html.BeginForm("AddShippingLocation", "Location", "POST"))
{
<input type="hidden" id="hdncountryid" />;
<input type="hidden" id="hdnstateid" />;
<input type="hidden" id="hdncityeid" />;
<input type="hidden" id="hdnAddress1" />;
<input type="hidden" id="hdnAddress2" />;
<input type="hidden" id="hdnZipCode" />;
<input type="hidden" id="hdnPhone" />;
<input type="hidden" id="hdnExtension" />;
<input type="hidden" id="hdnFax" />;
eCRM.Controllers.eCRM_Masters.LocationController dp = new eCRM.Controllers.eCRM_Masters.LocationController();
eCRM_Entity.eCRM_MastersEntities1 entities = new eCRM_Entity.eCRM_MastersEntities1();
List<SelectListItem> list = new List<SelectListItem>();
list.Add(new SelectListItem { Text = "-Select Country-", Value = "Selects items" });
var cat = (from c in entities.tbl_Country select c).ToArray();
for (int i = 0; i < cat.Length; i++)
{
list.Add(new SelectListItem
{
Text = cat[i].CountryName,
Value = cat[i].CountryId.ToString(),
Selected = (cat[i].CountryId == 0)
});
}
ViewData["danhsach"] = list;
<div>
<legend>***********Shipping Address**********</legend>
</div>
<div id='AppSelectorGroup'>
<div id="AppSelectorBox_1" style="display: block; float: left;">
<div class="editor-field">
@Html.DropDownList("CountryId", (IEnumerable<SelectListItem>)ViewData["danhsach"],
new { @class = "CssCategory", id = "CountryId" })
@Html.DropDownList("State_Id", new SelectList("State_Id", "StateName"), new { @class = "CssSubcategory", id = "State_Id" })
@Html.DropDownList("CityId", new SelectList("CityId", "CityName"), new { @class = "CssSubcategorycity", id = "CityId" })
Address1
@Html.TextBox("Address1", null, new { id = "Address11" })
Address2
@Html.TextBox("Address2", null, new { id = "Address21" })
ZipCode
@Html.TextBox("ZipCode", null, new { id = "ZipCode1" })
Phone
@Html.TextBox("Phone", null, new { id = "Phone1" })
Extension
@Html.TextBox("Extension", null, new { id = "Extension1" })
Fax
@Html.TextBox("Fax", null, new { id = "Fax1", @class = "deleteAppselector" })
</div>
</div>
<div class="clear-fix"></div>
</div>
<p>
<input type="submit" value="Save" name="Command" id="btn1" />
<input type="submit" value="Cancel" name="Command" />
</p>
//Page Validation
<script type="text/javascript">
$("#btn1").click(function (e) {
debugger;
// e.preventDefault();
var CountryId = $('#CountryId option:selected').val();
var StateId = $('#State_Id option:selected').val();
var CityId = $('#CityId option:selected').val();
if (CountryId == 0) {
alert("Please select country.")
return false;
}
if (StateId == 0) {
alert("Please select State.")
return false;
}
if (CityId == 0) {
alert("Please select City.")
return false;
}
var address1 = $("#Address11").val();
if (address1 == '') {
alert("Please enter address1");
return false;
}
var Address21 = $("#Address21").val();
if (Address21 == '') {
alert("Please enter Address2");
return false;
}
var ZipCode1 = $("#ZipCode1").val();
if (ZipCode1 == '') {
alert("Please enter ZipCode");
return false;
}
var Phone1 = $("#Phone1").val();
if (Phone1 == '') {
alert("Please enter Phone");
return false;
}
var Extension1 = $("#Extension1").val();
if (Extension1 == '') {
alert("Please enter Extension");
return false;
}
var Fax1 = $("#Fax1").val();
if (Fax1 == '') {
alert("Please enter Fax");
return false;
}
///////////////////////////
var hdncountryid = $("#hdncountryid").val();
var CountryId2 = $(hdncountryid + ' option:selected').val();
var hdnstateid = $("#hdnstateid").val();
var StateId2 = $(hdnstateid + ' option:selected').val();
var hdncityeid = $("#hdncityeid").val();
var Cityid2 = $(hdncityeid + ' option:selected').val();
///////////////////////////////
// var CountryId = $('#CountryId option:selected').val();
// var StateId = $('#State_Id option:selected').val();
// var CityId = $('#CityId option:selected').val();
if (CountryId2 == 0) {
alert("Please select country.")
return false;
}
if (StateId2 == 0) {
alert("Please select State.")
return false;
}
if (Cityid2 == 0) {
alert("Please select City.")
return false;
}
var address11 = $("#hdnAddress1").val();
if (address11 == '') {
alert("Please enter address1");
return false;
}
var Address212 = $("#hdnAddress2").val();
if (Address212 == '') {
alert("Please enter Address2");
return false;
}
var ZipCode12 = $("#hdnZipCode").val();
if (ZipCode12 == '') {
alert("Please enter ZipCode");
return false;
}
var Phone11 = $("#hdnPhone").val();
if (Phone11 == '') {
alert("Please enter Phone");
return false;
}
var Extension11 = $("#hdnExtension").val();
if (Extension11 == '') {
alert("Please enter Extension");
return false;
}
var Fax11 = $("#hdnFax").val();
if (Fax11 == '') {
alert("Please enter Fax");
return false;
}
});
$('#CountryId').change(function () {
var CountryId = $(this).val();
var URLS1 = '@Url.Action("GetState")' + '?CountryId=' + CountryId;
$.getJSON(URLS1, function (dataS1) {
$('#State_Id').html(dataS1);
});
});
$('#State_Id').change(function () {
var StateId = $(this).val();
var URLC1 = '@Url.Action("GetCity")' + '?StateId=' + StateId;
$.getJSON(URLC1, function (dataC1) {
$('#CityId').html(dataC1);
});
});
//Dropdown Selection Change event...
function onSelectChangeCountry() {
var hdncountryid = $("#hdncountryid").val();
var CountryId = $(hdncountryid + ' option:selected').val();
var URLS1 = '@Url.Action("GetState")' + '?CountryId=' + CountryId;
$.getJSON(URLS1, function (dataS1) {
var hdnstateid = $("#hdnstateid").val();
$(hdnstateid).html(dataS1);
});
}
function onSelectChangeState() {
var hdnstateid = $("#hdnstateid").val();
var StateId = $(hdnstateid + ' option:selected').val();
var URLC1 = '@Url.Action("GetCity")' + '?StateId=' + StateId;
$.getJSON(URLC1, function (dataC1) {
var hdncityeid = $("#hdncityeid").val();
$(hdncityeid).html(dataC1);
});
}
</script>
//Dynamic Code ...For Genrate DropDownlist and Text Boxs//
<script type="text/javascript">
//Jquery for handling the Click Event and Creating the Dynamic Controls:
//----------Begin: For Creating App Selector Groups---------------//
var deleteAppSelectror = $(".deleteAppselector").length;
/* For Adding the Control */
$("#addAppSelector").click(function () {
debugger;
if (deleteAppSelectror == 10) {
$("#addAppSelector").hide();
$("#removeAppSelector").show();
//alert("Only 10 URLs are allowed");
return false;
}
else {
$("#addAppSelector").show();
$("#removeAppSelector").show();
}
deleteAppSelectror++;
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'AppSelectorBox__' + deleteAppSelectror);
var URL = '@Url.Action("Getcountry")';
newTextBoxDiv.append('<div class="editor-label"><label>Shipping Address: </label></div>' +
'<select name="CountryId" onChange="onSelectChangeCountry();" id="CountryId' + deleteAppSelectror + '" class="valid" style = "width:80px"> </select>'
+
' <select name="State_Id" onChange="onSelectChangeState();" id="State_Id' + deleteAppSelectror + '" class="valid" style = "width:80px"> </select>' +
' <select name="CityId" id="CityId' + deleteAppSelectror + '" class="valid" style = "width:80px"> </select>' +
'Address1<div class="editor-field"><input type="text" name="Address1" id="Address1' + deleteAppSelectror + '" value="" />' +
'Address2<input type="text" name="Address2" id="Address2' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'ZipCode<input type="text" name="ZipCode" id="ZipCode' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'Phone<input type="text" name="Phone" id="Phone' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'Extension<input type="text" name="Extension" id="Extension' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'Fax<input type="text" name="Fax" class="deleteAppselector" id="Fax' + deleteAppSelectror + '" style="margin-left:8px;" value="" />' +
'</div><div class="clear-fix"></div>');
$.getJSON(URL, function (data) {
var ddlcountry = '#CountryId' + deleteAppSelectror;
$(ddlcountry).html(data);
var ddlstate = '#State_Id' + deleteAppSelectror;
var ddlcity = '#CityId' + deleteAppSelectror;
$("#hdncountryid").val(ddlcountry);
$("#hdnstateid").val(ddlstate);
$("#hdncityeid").val(ddlcity);
var Address1 = '#Address1' + deleteAppSelectror;
var Address2 = '#Address2' + deleteAppSelectror;
var ZipCode = '#ZipCode' + deleteAppSelectror;
var Phone = '#Phone' + deleteAppSelectror;
var Extension = '#Extension' + deleteAppSelectror;
var Fax = '#Fax' + deleteAppSelectror;
$("#hdnAddress1").val(Address1);
$("#hdnAddress2").val(Address2);
$("#hdnZipCode").val(ZipCode);
$("#hdnPhone").val(Phone);
$("#hdnExtension").val(Extension);
$("#hdnFax").val(Fax);
})
newTextBoxDiv.appendTo("#AppSelectorGroup");
if (deleteAppSelectror == 10) {
$("#addAppSelector").hide();
$("#removeAppSelector").show();
return false;
}
return true;
});
/* For Removing the Control */
$("#removeAppSelector").click(function () {
debugger;
if (deleteAppSelectror == 1) {
$("#removeAppSelector").hide();
$("#addAppSelector").show();
return false;
}
else {
$("#removeAppSelector").show();
$("#addAppSelector").show();
}
$('.deleteAppselector').last().parent().parent().remove();
deleteAppSelectror--;
if (deleteAppSelectror == 1) {
$("#removeAppSelector").hide();
$("#addAppSelector").show();
return false;
}
return true;
});
//----------End: For Creating App Selector Groups---------------//
</script>
}
Hope it will help u...enj...
Thursday, August 1, 2013
Entity Framework-Bind Data In Grid usind Stored Procedure -MVC4
Bind Data In Grid usind Stored Procedure:
Step1: Create Stored Procedure..
Step2: Create edmx File and Add Your table and Stored procddures...
Step3:Genrate Code Generation Form edmx file...
Step4: This For Only Get data from SP.
Step5:
Ofter Genrate Your Model1.Context.tt From .edmx file...
Add /Edit/Delete Operation From Stored Procedure:
set Parameters:
public virtual int xp_Potential_AddUpdateDelete(Nullable<int> potentialId, string potentialTitle, Nullable<int> potenOwnr_EmpID, string accountName, string accountId, string contactName, string contactId, string potential_Type, string primary_CampaginSrc, Nullable<System.DateTime> close_Date, Nullable<int> stageId, string probablity, string approxAmount_Product, string approxAmount_Services, string total_ApproxAmount, string nextStep, string description, Nullable<int> leadSourceId, Nullable<int> prev_TaskID_Active, Nullable<int> accnt_ActivityId, Nullable<int> user, Nullable<int> opration, ObjectParameter status)
{
var potentialIdParameter = potentialId.HasValue ?
new ObjectParameter("PotentialId", potentialId) :
new ObjectParameter("PotentialId", typeof(int));
var potentialTitleParameter = potentialTitle != null ?
new ObjectParameter("PotentialTitle", potentialTitle) :
new ObjectParameter("PotentialTitle", typeof(string));
var potenOwnr_EmpIDParameter = potenOwnr_EmpID.HasValue ?
new ObjectParameter("PotenOwnr_EmpID", potenOwnr_EmpID) :
new ObjectParameter("PotenOwnr_EmpID", typeof(int));
var accountNameParameter = accountName != null ?
new ObjectParameter("AccountName", accountName) :
new ObjectParameter("AccountName", typeof(string));
var accountIdParameter = accountId != null ?
new ObjectParameter("AccountId", accountId) :
new ObjectParameter("AccountId", typeof(string));
var contactNameParameter = contactName != null ?
new ObjectParameter("ContactName", contactName) :
new ObjectParameter("ContactName", typeof(string));
var contactIdParameter = contactId != null ?
new ObjectParameter("ContactId", contactId) :
new ObjectParameter("ContactId", typeof(string));
var potential_TypeParameter = potential_Type != null ?
new ObjectParameter("Potential_Type", potential_Type) :
new ObjectParameter("Potential_Type", typeof(string));
var primary_CampaginSrcParameter = primary_CampaginSrc != null ?
new ObjectParameter("Primary_CampaginSrc", primary_CampaginSrc) :
new ObjectParameter("Primary_CampaginSrc", typeof(string));
var close_DateParameter = close_Date.HasValue ?
new ObjectParameter("Close_Date", close_Date) :
new ObjectParameter("Close_Date", typeof(System.DateTime));
var stageIdParameter = stageId.HasValue ?
new ObjectParameter("StageId", stageId) :
new ObjectParameter("StageId", typeof(int));
var probablityParameter = probablity != null ?
new ObjectParameter("Probablity", probablity) :
new ObjectParameter("Probablity", typeof(string));
var approxAmount_ProductParameter = approxAmount_Product != null ?
new ObjectParameter("ApproxAmount_Product", approxAmount_Product) :
new ObjectParameter("ApproxAmount_Product", typeof(string));
var approxAmount_ServicesParameter = approxAmount_Services != null ?
new ObjectParameter("ApproxAmount_Services", approxAmount_Services) :
new ObjectParameter("ApproxAmount_Services", typeof(string));
var total_ApproxAmountParameter = total_ApproxAmount != null ?
new ObjectParameter("Total_ApproxAmount", total_ApproxAmount) :
new ObjectParameter("Total_ApproxAmount", typeof(string));
var nextStepParameter = nextStep != null ?
new ObjectParameter("NextStep", nextStep) :
new ObjectParameter("NextStep", typeof(string));
var descriptionParameter = description != null ?
new ObjectParameter("Description", description) :
new ObjectParameter("Description", typeof(string));
var leadSourceIdParameter = leadSourceId.HasValue ?
new ObjectParameter("LeadSourceId", leadSourceId) :
new ObjectParameter("LeadSourceId", typeof(int));
var prev_TaskID_ActiveParameter = prev_TaskID_Active.HasValue ?
new ObjectParameter("Prev_TaskID_Active", prev_TaskID_Active) :
new ObjectParameter("Prev_TaskID_Active", typeof(int));
var accnt_ActivityIdParameter = accnt_ActivityId.HasValue ?
new ObjectParameter("Accnt_ActivityId", accnt_ActivityId) :
new ObjectParameter("Accnt_ActivityId", typeof(int));
var userParameter = user.HasValue ?
new ObjectParameter("user", user) :
new ObjectParameter("user", typeof(int));
var oprationParameter = opration.HasValue ?
new ObjectParameter("opration", opration) :
new ObjectParameter("opration", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("xp_Potential_AddUpdateDelete", potentialIdParameter, potentialTitleParameter, potenOwnr_EmpIDParameter, accountNameParameter, accountIdParameter, contactNameParameter, contactIdParameter, potential_TypeParameter, primary_CampaginSrcParameter, close_DateParameter, stageIdParameter, probablityParameter, approxAmount_ProductParameter, approxAmount_ServicesParameter, total_ApproxAmountParameter, nextStepParameter, descriptionParameter, leadSourceIdParameter, prev_TaskID_ActiveParameter, accnt_ActivityIdParameter, userParameter, oprationParameter, status);
}
And Get Data Function:
public virtual ObjectResult<xp_getAllPotential_Result> xp_getAllPotential()
{
((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(xp_getAllPotential_Result).Assembly);
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<xp_getAllPotential_Result>("xp_getAllPotential");
}
Controllers Class:
Add/Edit/Delete for Sp:
[HttpPost]
public ActionResult CreateEditPotential(CS_Potential mCust, string Command)
{
// Validate the model being submitted
int oprat = Convert.ToInt32(Command);
if (!ModelState.IsValid)
{
return PartialView("_Potential", mCust);
}
tbl_Potential mobjcust=new tbl_Potential();
if (oprat == 0)
{
mobjcust.PotentialId = 0;
}
else
{
mobjcust.PotentialId = mCust.PotentialId;
oprat = 0;
}
mobjcust.PotentialTitle=mCust.PotentialTitle;
mobjcust.PotenOwnr_EmpID=mCust.PotenOwnr_EmpID;
mobjcust.AccountName=mCust.AccountName;
mobjcust.AccountId=mCust.AccountId;
mobjcust.ContactName=mCust.ContactName;
mobjcust.ContactId=mCust.ContactId;
mobjcust.Potential_Type=mCust.Potential_Type;
mobjcust.Primary_CampaginSrc = mCust.Primary_CampaginSrc;
mobjcust.Close_Date=null;//mCust.Close_Date
mobjcust.StageId=null;//mCust.StageId
mobjcust.Probablity="";//mCust.Probablity
mobjcust.ApproxAmount_Product="";//mCust.ApproxAmount_Product
mobjcust.ApproxAmount_Services="";//mCust.ApproxAmount_Services
mobjcust.Total_ApproxAmount="";//mCust.Total_ApproxAmount
mobjcust.NextStep="";//mCust.NextStep
mobjcust.Description="";//mCust.Description
mobjcust.LeadSourceId=null;//mCust.LeadSourceId
mobjcust.Prev_TaskID_Active = 1;// null;//mCust.Prev_TaskID_Active
mobjcust.Accnt_ActivityId=null;//mCust.Accnt_ActivityId
mobjcust.CreatedBy=1;//mCust.CreatedBy
int check = mobjModel.Potential_AddUpdateDelete(mobjcust, oprat);
if (check == 2 || check == 3 || check == 4)
{
TempData["Msg"] = "Data has been saved succeessfully";
ModelState.Clear();
return RedirectToAction("TaskPotentialGrid", "C_Potential");
}
return PartialView("_Potential");
}
public ActionResult Edit(int id)
{
var data = mobjModel.GetPotential1(id);
if (Request.IsAjaxRequest())
{
CS_Potential cust = new CS_Potential();
cust.PotentialTitle = data.PotentialTitle;
cust.PotentialId = data.PotentialId;
cust.PotenOwnr_EmpID = data.PotenOwnr_EmpID;
cust.AccountName = data.AccountName;
cust.AccountId = data.AccountId;
cust.ContactName = data.ContactName;
cust.ContactId = data.ContactId;
cust.Potential_Type = data.Potential_Type;
cust.Primary_CampaginSrc = data.Primary_CampaginSrc;
ViewData["EmpTitle"] = GetUsers();
ViewBag.IsUpdate = true;
return View("_Potential", cust);
}
else
return View(data);
}
public ActionResult Delete(int id)
{
tbl_Potential mobjcust = new tbl_Potential();
int oprat = 1;
mobjcust.PotentialId= id;
mobjcust.Prev_TaskID_Active = 18;
int check = mobjModel.Potential_AddUpdateDelete(mobjcust,oprat);
if (check==4)
{
TempData["Msg"] = "Data has been Deleted succeessfully";
ModelState.Clear();
return RedirectToAction("TaskPotentialGrid", "C_Potential");
}
else
{
return PartialView("_Potential");
}
}
Get Data Function For Bind :
public ActionResult TaskPotentialGrid(int page = 1, string sort = "name", string sortDir = "ASC")
{
const int pageSize = 5;
var totalRows = mobjModel.CountPotential();
sortDir = sortDir.Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? sortDir : "asc";
var validColumns = new[] { "TaskStatusId", "TaskStatus", "CreatedDate", "IsActive" };
if (!validColumns.Any(c => c.Equals(sort, StringComparison.CurrentCultureIgnoreCase)))
sort = "TaskStatusId";
var task = mobjModel.GetPotentialPage(page, pageSize, "it." + sort + " " + sortDir);
var data = new PagedCustomerModel()
{
TotalRows = totalRows,
PageSize = pageSize,
Task = task
};
return View(data);
}
Model Class Code:
Add/Edit/Delete for Sp:
public int Potential_AddUpdateDelete(tbl_Potential Pt,int opration)
{
if (Pt.PotentialId == 0 && opration==0) //Add
{
AllOpration(Pt, opration);
return 2;
}
else if (Pt.PotentialId > 0 && opration==1) //Delete
{
AllOpration(Pt, opration);
return 4;
}
else if (Pt.PotentialId > 0 && opration==0) //update
{
AllOpration(Pt, opration);
return 3;
}
else
{
return 1;
}
}
public bool AllOpration(tbl_Potential Pt, int oprat)
{
System.Data.Entity.Core.Objects.ObjectParameter result = new System.Data.Entity.Core.Objects.ObjectParameter("Status", typeof(int));
result.Value = DBNull.Value;
entities.xp_Potential_AddUpdateDelete(Pt.PotentialId, Pt.PotentialTitle, Pt.PotenOwnr_EmpID, Pt.AccountName, Pt.AccountId, Pt.ContactName, Pt.ContactId, Pt.Potential_Type, Pt.Primary_CampaginSrc, Pt.Close_Date, Pt.StageId, Pt.Probablity, Pt.ApproxAmount_Product, Pt.ApproxAmount_Services, Pt.Total_ApproxAmount, Pt.NextStep, Pt.Description, Pt.LeadSourceId, Pt.Prev_TaskID_Active, Pt.Accnt_ActivityId, Pt.CreatedBy, oprat, result);
if (result.Equals(2) || result.Equals(3) || result.Equals(4))
{
return true;
}
else
{
return false;
}
//return false;
}
Get data For .edmx file
public List<CS_Potential> GetPotentialPage(int pageNumber, int pageSize, string searchCriteria)
{
if (pageNumber < 1)
pageNumber = 1;
// return entities.xp_getAllPotential();
// .OrderBy(searchCriteria)
//.Skip((pageNumber - 1) * pageSize)
//.Take(pageSize)
//.ToList();
entities=new eCRM_MastersEntities1();
var data =
(from pt in entities.xp_getAllPotential()
select new CS_Potential
{
PotentialId = pt.PotentialId,
PotentialTitle = pt.PotentialTitle,
Name=pt.Name,
AccountName=pt.AccountName,
ContactName = pt.ContactName,
ContactId = pt.ContactId,
AccountId=pt.AccountId
}
).ToList();
return data;
}
View Page:
@model BAL.MS_PotentialMaster
@{
ViewBag.Title = "M_Potential";
WebGrid grid = new WebGrid(rowsPerPage: Model.PageSize);
if(Model.TotalRows>0)
{
grid.Bind(Model.Potential,
autoSortAndPage: false,
rowCount: Model.TotalRows);
}
}
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<link href="../../Content/themes/base/minified/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#CreateCustomer").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-edit").dialog({
title: 'Create Potential Stage',
autoOpen: false,
resizable: false,
height: 200,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-edit").dialog('open');
return false;
});
$(".editDialog").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-edit").dialog({
title: 'Edit Potential Stage',
autoOpen: false,
resizable: false,
height: 200,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-edit").dialog('open');
return false;
});
$(".confirmDialog").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: 170,
width: 350,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location = url;
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog('open');
return false;
});
$(".viewDialog").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-view").dialog({
title: 'View Potential Stage',
autoOpen: false,
resizable: false,
height: 150,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-view").dialog('open');
return false;
});
$("#btncancel").live("click", function (e) {
// location.reload(true);
$("#dialog-edit").dialog('close');
});
});
</script>
@using (Html.BeginForm("M_Potential", "M_Potential", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<table style="margin-top:10px; border:1 solid Gray; padding-top:50;" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<div style="color: Red; font-weight:bold;">
@TempData["msg"]
<br />
</div>
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.PotentialStage)
</td>
<td>
@Html.TextBoxFor(m => m.PotentialStage)
<span style=" color:Red;">
@Html.ValidationMessageFor(m => m.PotentialStage)
</span>
</td>
</tr>
<tr>
<td></td>
<td align="left" >
<input type="submit" value="Add potential Stage" id="btnSubmit" />
</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">
<div>
@if (Model.PotentialStageId > 0)
{
@* <table style="margin-top:10px; border:1 solid Gray; padding-top:50;" cellpadding="0" cellspacing="0">
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.PotentialStage)
</td>
<td class="editor-field">
@Html.DisplayTextFor(model => model.PotentialStage)
</td>
</tr>
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.CreatedDate)
</td>
<td class="editor-field">
@Html.DisplayTextFor(model => model.CreatedDate)
</td>
</tr>
</table>
*@
}
</div>
@if (Model.TotalRows > 0)
{
<br />
@grid.GetHtml(
fillEmptyRows: false,
tableStyle:"WebGrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style", htmlAttributes: new { id = "grid" },
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("PotentialStageId", header: "Stage ID", canSort: false),
grid.Column("PotentialStage", header: "Stage Name",
format: @<text> @Html.ActionLink((string)item.PotentialStage, "View", new { id = item.PotentialStageId }, new { @class = "viewDialog" })</text>
),
grid.Column("CreatedDate", header: "Created Date",format: (item) => string.Format("{0:dd-MMM-yyyy}", item.CreatedDate)),
grid.Column("", header: "Actions",format: @<text>
@Html.ActionLink("Edit", "Edit", new { id = item.PotentialStageId }, new { @class = "editDialog"/*, data_dialog_id = "edit-Dialog"*/ })
| @Html.ActionLink("Delete", "Delete", new { id = item.PotentialStageId }, new { @class = "confirmDialog" })
</text>
)
})
}
else
{
<p>No data found.</p>
}
</td>
</tr>
</table>
<div id="dialog-confirm" style="display: none">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure to delete ?
</p>
</div>
<div id="dialog-edit" style="display: none">
</div>
<div id="dialog-view" style="display: none">
</div>
}
Hope It will Help You...Enj..
Code Written by Anjum Syend and me...
Step1: Create Stored Procedure..
Step2: Create edmx File and Add Your table and Stored procddures...
Step3:Genrate Code Generation Form edmx file...
Step4: This For Only Get data from SP.
Step5:
Ofter Genrate Your Model1.Context.tt From .edmx file...
Add /Edit/Delete Operation From Stored Procedure:
set Parameters:
public virtual int xp_Potential_AddUpdateDelete(Nullable<int> potentialId, string potentialTitle, Nullable<int> potenOwnr_EmpID, string accountName, string accountId, string contactName, string contactId, string potential_Type, string primary_CampaginSrc, Nullable<System.DateTime> close_Date, Nullable<int> stageId, string probablity, string approxAmount_Product, string approxAmount_Services, string total_ApproxAmount, string nextStep, string description, Nullable<int> leadSourceId, Nullable<int> prev_TaskID_Active, Nullable<int> accnt_ActivityId, Nullable<int> user, Nullable<int> opration, ObjectParameter status)
{
var potentialIdParameter = potentialId.HasValue ?
new ObjectParameter("PotentialId", potentialId) :
new ObjectParameter("PotentialId", typeof(int));
var potentialTitleParameter = potentialTitle != null ?
new ObjectParameter("PotentialTitle", potentialTitle) :
new ObjectParameter("PotentialTitle", typeof(string));
var potenOwnr_EmpIDParameter = potenOwnr_EmpID.HasValue ?
new ObjectParameter("PotenOwnr_EmpID", potenOwnr_EmpID) :
new ObjectParameter("PotenOwnr_EmpID", typeof(int));
var accountNameParameter = accountName != null ?
new ObjectParameter("AccountName", accountName) :
new ObjectParameter("AccountName", typeof(string));
var accountIdParameter = accountId != null ?
new ObjectParameter("AccountId", accountId) :
new ObjectParameter("AccountId", typeof(string));
var contactNameParameter = contactName != null ?
new ObjectParameter("ContactName", contactName) :
new ObjectParameter("ContactName", typeof(string));
var contactIdParameter = contactId != null ?
new ObjectParameter("ContactId", contactId) :
new ObjectParameter("ContactId", typeof(string));
var potential_TypeParameter = potential_Type != null ?
new ObjectParameter("Potential_Type", potential_Type) :
new ObjectParameter("Potential_Type", typeof(string));
var primary_CampaginSrcParameter = primary_CampaginSrc != null ?
new ObjectParameter("Primary_CampaginSrc", primary_CampaginSrc) :
new ObjectParameter("Primary_CampaginSrc", typeof(string));
var close_DateParameter = close_Date.HasValue ?
new ObjectParameter("Close_Date", close_Date) :
new ObjectParameter("Close_Date", typeof(System.DateTime));
var stageIdParameter = stageId.HasValue ?
new ObjectParameter("StageId", stageId) :
new ObjectParameter("StageId", typeof(int));
var probablityParameter = probablity != null ?
new ObjectParameter("Probablity", probablity) :
new ObjectParameter("Probablity", typeof(string));
var approxAmount_ProductParameter = approxAmount_Product != null ?
new ObjectParameter("ApproxAmount_Product", approxAmount_Product) :
new ObjectParameter("ApproxAmount_Product", typeof(string));
var approxAmount_ServicesParameter = approxAmount_Services != null ?
new ObjectParameter("ApproxAmount_Services", approxAmount_Services) :
new ObjectParameter("ApproxAmount_Services", typeof(string));
var total_ApproxAmountParameter = total_ApproxAmount != null ?
new ObjectParameter("Total_ApproxAmount", total_ApproxAmount) :
new ObjectParameter("Total_ApproxAmount", typeof(string));
var nextStepParameter = nextStep != null ?
new ObjectParameter("NextStep", nextStep) :
new ObjectParameter("NextStep", typeof(string));
var descriptionParameter = description != null ?
new ObjectParameter("Description", description) :
new ObjectParameter("Description", typeof(string));
var leadSourceIdParameter = leadSourceId.HasValue ?
new ObjectParameter("LeadSourceId", leadSourceId) :
new ObjectParameter("LeadSourceId", typeof(int));
var prev_TaskID_ActiveParameter = prev_TaskID_Active.HasValue ?
new ObjectParameter("Prev_TaskID_Active", prev_TaskID_Active) :
new ObjectParameter("Prev_TaskID_Active", typeof(int));
var accnt_ActivityIdParameter = accnt_ActivityId.HasValue ?
new ObjectParameter("Accnt_ActivityId", accnt_ActivityId) :
new ObjectParameter("Accnt_ActivityId", typeof(int));
var userParameter = user.HasValue ?
new ObjectParameter("user", user) :
new ObjectParameter("user", typeof(int));
var oprationParameter = opration.HasValue ?
new ObjectParameter("opration", opration) :
new ObjectParameter("opration", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("xp_Potential_AddUpdateDelete", potentialIdParameter, potentialTitleParameter, potenOwnr_EmpIDParameter, accountNameParameter, accountIdParameter, contactNameParameter, contactIdParameter, potential_TypeParameter, primary_CampaginSrcParameter, close_DateParameter, stageIdParameter, probablityParameter, approxAmount_ProductParameter, approxAmount_ServicesParameter, total_ApproxAmountParameter, nextStepParameter, descriptionParameter, leadSourceIdParameter, prev_TaskID_ActiveParameter, accnt_ActivityIdParameter, userParameter, oprationParameter, status);
}
And Get Data Function:
public virtual ObjectResult<xp_getAllPotential_Result> xp_getAllPotential()
{
((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(xp_getAllPotential_Result).Assembly);
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<xp_getAllPotential_Result>("xp_getAllPotential");
}
Controllers Class:
Add/Edit/Delete for Sp:
[HttpPost]
public ActionResult CreateEditPotential(CS_Potential mCust, string Command)
{
// Validate the model being submitted
int oprat = Convert.ToInt32(Command);
if (!ModelState.IsValid)
{
return PartialView("_Potential", mCust);
}
tbl_Potential mobjcust=new tbl_Potential();
if (oprat == 0)
{
mobjcust.PotentialId = 0;
}
else
{
mobjcust.PotentialId = mCust.PotentialId;
oprat = 0;
}
mobjcust.PotentialTitle=mCust.PotentialTitle;
mobjcust.PotenOwnr_EmpID=mCust.PotenOwnr_EmpID;
mobjcust.AccountName=mCust.AccountName;
mobjcust.AccountId=mCust.AccountId;
mobjcust.ContactName=mCust.ContactName;
mobjcust.ContactId=mCust.ContactId;
mobjcust.Potential_Type=mCust.Potential_Type;
mobjcust.Primary_CampaginSrc = mCust.Primary_CampaginSrc;
mobjcust.Close_Date=null;//mCust.Close_Date
mobjcust.StageId=null;//mCust.StageId
mobjcust.Probablity="";//mCust.Probablity
mobjcust.ApproxAmount_Product="";//mCust.ApproxAmount_Product
mobjcust.ApproxAmount_Services="";//mCust.ApproxAmount_Services
mobjcust.Total_ApproxAmount="";//mCust.Total_ApproxAmount
mobjcust.NextStep="";//mCust.NextStep
mobjcust.Description="";//mCust.Description
mobjcust.LeadSourceId=null;//mCust.LeadSourceId
mobjcust.Prev_TaskID_Active = 1;// null;//mCust.Prev_TaskID_Active
mobjcust.Accnt_ActivityId=null;//mCust.Accnt_ActivityId
mobjcust.CreatedBy=1;//mCust.CreatedBy
int check = mobjModel.Potential_AddUpdateDelete(mobjcust, oprat);
if (check == 2 || check == 3 || check == 4)
{
TempData["Msg"] = "Data has been saved succeessfully";
ModelState.Clear();
return RedirectToAction("TaskPotentialGrid", "C_Potential");
}
return PartialView("_Potential");
}
public ActionResult Edit(int id)
{
var data = mobjModel.GetPotential1(id);
if (Request.IsAjaxRequest())
{
CS_Potential cust = new CS_Potential();
cust.PotentialTitle = data.PotentialTitle;
cust.PotentialId = data.PotentialId;
cust.PotenOwnr_EmpID = data.PotenOwnr_EmpID;
cust.AccountName = data.AccountName;
cust.AccountId = data.AccountId;
cust.ContactName = data.ContactName;
cust.ContactId = data.ContactId;
cust.Potential_Type = data.Potential_Type;
cust.Primary_CampaginSrc = data.Primary_CampaginSrc;
ViewData["EmpTitle"] = GetUsers();
ViewBag.IsUpdate = true;
return View("_Potential", cust);
}
else
return View(data);
}
public ActionResult Delete(int id)
{
tbl_Potential mobjcust = new tbl_Potential();
int oprat = 1;
mobjcust.PotentialId= id;
mobjcust.Prev_TaskID_Active = 18;
int check = mobjModel.Potential_AddUpdateDelete(mobjcust,oprat);
if (check==4)
{
TempData["Msg"] = "Data has been Deleted succeessfully";
ModelState.Clear();
return RedirectToAction("TaskPotentialGrid", "C_Potential");
}
else
{
return PartialView("_Potential");
}
}
Get Data Function For Bind :
public ActionResult TaskPotentialGrid(int page = 1, string sort = "name", string sortDir = "ASC")
{
const int pageSize = 5;
var totalRows = mobjModel.CountPotential();
sortDir = sortDir.Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? sortDir : "asc";
var validColumns = new[] { "TaskStatusId", "TaskStatus", "CreatedDate", "IsActive" };
if (!validColumns.Any(c => c.Equals(sort, StringComparison.CurrentCultureIgnoreCase)))
sort = "TaskStatusId";
var task = mobjModel.GetPotentialPage(page, pageSize, "it." + sort + " " + sortDir);
var data = new PagedCustomerModel()
{
TotalRows = totalRows,
PageSize = pageSize,
Task = task
};
return View(data);
}
Model Class Code:
Add/Edit/Delete for Sp:
public int Potential_AddUpdateDelete(tbl_Potential Pt,int opration)
{
if (Pt.PotentialId == 0 && opration==0) //Add
{
AllOpration(Pt, opration);
return 2;
}
else if (Pt.PotentialId > 0 && opration==1) //Delete
{
AllOpration(Pt, opration);
return 4;
}
else if (Pt.PotentialId > 0 && opration==0) //update
{
AllOpration(Pt, opration);
return 3;
}
else
{
return 1;
}
}
public bool AllOpration(tbl_Potential Pt, int oprat)
{
System.Data.Entity.Core.Objects.ObjectParameter result = new System.Data.Entity.Core.Objects.ObjectParameter("Status", typeof(int));
result.Value = DBNull.Value;
entities.xp_Potential_AddUpdateDelete(Pt.PotentialId, Pt.PotentialTitle, Pt.PotenOwnr_EmpID, Pt.AccountName, Pt.AccountId, Pt.ContactName, Pt.ContactId, Pt.Potential_Type, Pt.Primary_CampaginSrc, Pt.Close_Date, Pt.StageId, Pt.Probablity, Pt.ApproxAmount_Product, Pt.ApproxAmount_Services, Pt.Total_ApproxAmount, Pt.NextStep, Pt.Description, Pt.LeadSourceId, Pt.Prev_TaskID_Active, Pt.Accnt_ActivityId, Pt.CreatedBy, oprat, result);
if (result.Equals(2) || result.Equals(3) || result.Equals(4))
{
return true;
}
else
{
return false;
}
//return false;
}
Get data For .edmx file
public List<CS_Potential> GetPotentialPage(int pageNumber, int pageSize, string searchCriteria)
{
if (pageNumber < 1)
pageNumber = 1;
// return entities.xp_getAllPotential();
// .OrderBy(searchCriteria)
//.Skip((pageNumber - 1) * pageSize)
//.Take(pageSize)
//.ToList();
entities=new eCRM_MastersEntities1();
var data =
(from pt in entities.xp_getAllPotential()
select new CS_Potential
{
PotentialId = pt.PotentialId,
PotentialTitle = pt.PotentialTitle,
Name=pt.Name,
AccountName=pt.AccountName,
ContactName = pt.ContactName,
ContactId = pt.ContactId,
AccountId=pt.AccountId
}
).ToList();
return data;
}
View Page:
@model BAL.MS_PotentialMaster
@{
ViewBag.Title = "M_Potential";
WebGrid grid = new WebGrid(rowsPerPage: Model.PageSize);
if(Model.TotalRows>0)
{
grid.Bind(Model.Potential,
autoSortAndPage: false,
rowCount: Model.TotalRows);
}
}
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<link href="../../Content/themes/base/minified/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#CreateCustomer").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-edit").dialog({
title: 'Create Potential Stage',
autoOpen: false,
resizable: false,
height: 200,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-edit").dialog('open');
return false;
});
$(".editDialog").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-edit").dialog({
title: 'Edit Potential Stage',
autoOpen: false,
resizable: false,
height: 200,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-edit").dialog('open');
return false;
});
$(".confirmDialog").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: 170,
width: 350,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location = url;
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog('open');
return false;
});
$(".viewDialog").live("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-view").dialog({
title: 'View Potential Stage',
autoOpen: false,
resizable: false,
height: 150,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
},
close: function (event, ui) {
$(this).dialog('close');
}
});
$("#dialog-view").dialog('open');
return false;
});
$("#btncancel").live("click", function (e) {
// location.reload(true);
$("#dialog-edit").dialog('close');
});
});
</script>
@using (Html.BeginForm("M_Potential", "M_Potential", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<table style="margin-top:10px; border:1 solid Gray; padding-top:50;" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<div style="color: Red; font-weight:bold;">
@TempData["msg"]
<br />
</div>
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.PotentialStage)
</td>
<td>
@Html.TextBoxFor(m => m.PotentialStage)
<span style=" color:Red;">
@Html.ValidationMessageFor(m => m.PotentialStage)
</span>
</td>
</tr>
<tr>
<td></td>
<td align="left" >
<input type="submit" value="Add potential Stage" id="btnSubmit" />
</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">
<div>
@if (Model.PotentialStageId > 0)
{
@* <table style="margin-top:10px; border:1 solid Gray; padding-top:50;" cellpadding="0" cellspacing="0">
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.PotentialStage)
</td>
<td class="editor-field">
@Html.DisplayTextFor(model => model.PotentialStage)
</td>
</tr>
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.CreatedDate)
</td>
<td class="editor-field">
@Html.DisplayTextFor(model => model.CreatedDate)
</td>
</tr>
</table>
*@
}
</div>
@if (Model.TotalRows > 0)
{
<br />
@grid.GetHtml(
fillEmptyRows: false,
tableStyle:"WebGrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style", htmlAttributes: new { id = "grid" },
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("PotentialStageId", header: "Stage ID", canSort: false),
grid.Column("PotentialStage", header: "Stage Name",
format: @<text> @Html.ActionLink((string)item.PotentialStage, "View", new { id = item.PotentialStageId }, new { @class = "viewDialog" })</text>
),
grid.Column("CreatedDate", header: "Created Date",format: (item) => string.Format("{0:dd-MMM-yyyy}", item.CreatedDate)),
grid.Column("", header: "Actions",format: @<text>
@Html.ActionLink("Edit", "Edit", new { id = item.PotentialStageId }, new { @class = "editDialog"/*, data_dialog_id = "edit-Dialog"*/ })
| @Html.ActionLink("Delete", "Delete", new { id = item.PotentialStageId }, new { @class = "confirmDialog" })
</text>
)
})
}
else
{
<p>No data found.</p>
}
</td>
</tr>
</table>
<div id="dialog-confirm" style="display: none">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure to delete ?
</p>
</div>
<div id="dialog-edit" style="display: none">
</div>
<div id="dialog-view" style="display: none">
</div>
}
Hope It will Help You...Enj..
Code Written by Anjum Syend and me...
Subscribe to:
Posts (Atom)