1, List page(aspx.cs)
if (resultList.ElementAt(i).frequency == -1)
{
listStr += "<td class='" + styleClass + "'> Closed <div class='showAslink' href='' οnclick='ajaxChangeStatusForEmailReport(" + resultList.ElementAt(i).idAgent + "," + 0 + ")'>TurnOn</div></td>";
}
else if (resultList.ElementAt(i).frequency == 0)
{
listStr += "<td class='" + styleClass + "'>" + "Unopen!" + "</span> <div class='showAslink' href='' οnclick='ajaxChangeStatusForEmailReport(" + resultList.ElementAt(i).idAgent + "," + 1 + ")'>Open</div></td>";
}
else
{
listStr += "<td class='" + styleClass + "'>" + resultList.ElementAt(i).frequency + " Day <div class='showAslink' href='' οnclick='ajaxChangeStatusForEmailReport(" + resultList.ElementAt(i).idAgent + "," + 2 + ")'>TurnOff</div></td>";
}
//************ template ************
if (resultList.ElementAt(i).Template == 0)
{ listStr += "<td class='" + styleClass + "'> Default " + " <div class='showAslink' href='' οnclick='ajaxChangeTemplateForEmailReport(" + resultList.ElementAt(i).idAgent + "," + 0 + ")'>Change</div> </td>"; }
else if (resultList.ElementAt(i).Template == 1)
{ listStr += "<td class='" + styleClass + "'> Onview " + " <div class='showAslink' href='' οnclick='ajaxChangeTemplateForEmailReport(" + resultList.ElementAt(i).idAgent + "," + 1 + ")'>Change</div> </td>"; }
else
{ listStr += "<td class='" + styleClass + "'> Other </td>"; }
if (crule == 1)
{
listStr += "<td class='" + styleClass + "'>" + "Online" + "</span> <div class='showAslink' href='' οnclick='ajaxChangeStatusOfProperty(" + resultList.ElementAt(i).idList + "," + 2 + ")'>Turn Off</div> </td>";
}
else
{
listStr += "<td class='" + styleClass + "'>" + "Offline" + "</span> <div class='showAslink' href='' οnclick='ajaxChangeStatusOfProperty(" + resultList.ElementAt(i).idList + "," + 1 + ")'>Turn On</div> </td>";
}
2,AjaxResponse page(aspx.cs)
//######################## WebMethods for called form Ajax ##############################
[WebMethod]
public static string AjaxControl_emailalert(int IdAgent, int Status)
{
using (var dc = new DAL.findahome.findahomeDataContext())
{
try
{
string returnMessage = "";
var freq = dc.AgentContactFrequencies.Where(c => c.AgentId == IdAgent).FirstOrDefault();
if (Status.Equals(0))
{
freq.Frequency = 7;
returnMessage = "The Email Report has been turn on!";
}
else if (Status.Equals(1))
{
AgentContactFrequency acf = new AgentContactFrequency();
acf.AgentId = IdAgent;
acf.Frequency = 7;
acf.Template = 0;
dc.AgentContactFrequencies.InsertOnSubmit(acf);
returnMessage = "The Email Report has been open!";
}
else if (Status.Equals(2))
{
freq.Frequency = -1;
returnMessage = "The Email Report has been Turn Off!";
}
dc.SubmitChanges();
return returnMessage;
}
catch (Exception e)
{
return "An error occur!";
}
}
}
[WebMethod]
public static string Ajax_ChangeReportTemplate(int idAgent, int IDtemplate)
{
using (var dc = new DAL.findahome.findahomeDataContext())
{
try
{
string returnMessage = "";
var t = dc.AgentContactFrequencies.Where(c => c.AgentId == idAgent).FirstOrDefault();
if (IDtemplate.Equals(0))
{
t.Template = 1; // change template to onview
returnMessage = "The Template has been changed as Onview!";
}
else if (IDtemplate.Equals(1))
{
t.Template = 0; // change template to default
returnMessage = "The Template has been changed as Default!";
}
dc.SubmitChanges();
return returnMessage;
}
catch (Exception e)
{
return e.Message;
}
}
}
[WebMethod]
public static string AjaxChange_PropertyCRule(int idList, int status)
{
using (var dc = new DAL.findahome.findahomeDataContext())
{
try
{
var prop = dc.Properties.Where(c => c.idList == idList).FirstOrDefault();
string returnMessage = "";
if (status.Equals(1))
{
prop.idCRule = 1;
returnMessage = "The Property has been take online!";
}
else if (status.Equals(2))
{
prop.idCRule = 2;
returnMessage = "The Property has been take offline!";
}
dc.SubmitChanges();
return returnMessage;
}
catch (Exception e)
{
return e.Message;
}
}
}
3, Ajax by Jquery(Js)
var idAgent;
var status;
function ajaxChangeStatusForEmailReport(idAgent, status) {
var nextstatus = ((status == 2) ? "Off" : "On");
if (confirm("Are you sure to Turn" + nextstatus + " Email Report?")) {
$.ajax({
type: "POST",
url: "ajaxResponse.aspx/AjaxControl_emailalert",
data: '{IdAgent:"' + idAgent + '", Status:"' + status + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function () {
alert("An unexpected error has occurred during processing.");
}
});
}
}
var IDtemplate;
function ajaxChangeTemplateForEmailReport(idAgent, IDtemplate) {
var nextTemplate = ((IDtemplate == 0) ? "Onview.ie" : "Default");
if (confirm("Are you sure to change Email Report Template as " + nextTemplate + "?")) {
$.ajax({
type: "POST",
url: "ajaxResponse.aspx/Ajax_ChangeReportTemplate",
data: '{idAgent:"' + idAgent + '", IDtemplate:"' + IDtemplate + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function () {
alert("An unexpected error has occurred during processing.");
}
});
}
}
var idList;
function ajaxChangeStatusOfProperty(idList, status) {
var nextstatus = ((status == 1) ? "online" : "offline");
if (confirm("Are you sure to take " + nextstatus + " this property?")) {
$.ajax({
type: "POST",
url: "ajaxResponse.aspx/AjaxChange_PropertyCRule",
data: '{idList:"' + idList + '", status:"' + status + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function () {
alert("An unexpected error has occurred during processing.");
}
});
}
}