|
||||||||||||||
<link rel="stylesheet" type="text/css" href="dbnetsuite.css.ashx" /> <script language="JavaScript" src="dbnetsuite.js.ashx"></script>
<script>
jQuery(document).ready( init )
////////////////////////////////////////////////////////////
function init()
////////////////////////////////////////////////////////////
{
var dbnetgrid1 = new DbNetGrid("dbnetgrid1");
with (dbnetgrid1)
{
connectionString = "SamplesDatabase"
fromPart = "Suppliers"
bind("onRecordDeleted", window.recordDeleted)
bind("onRecordInserted", window.recordInserted)
bind("onRecordUpdated", window.recordUpdated)
initialize()
}
}
////////////////////////////////////////////////////////////
function recordDeleted(sender, args)
////////////////////////////////////////////////////////////
{
sendMessage(args.deleted[0].companyname, "deleted");
}
////////////////////////////////////////////////////////////
function recordInserted(sender, args)
////////////////////////////////////////////////////////////
{
sendMessage(args.inserted.companyname, "inserted");
}
////////////////////////////////////////////////////////////
function recordUpdated(sender, args)
////////////////////////////////////////////////////////////
{
sendMessage( args.updated.companyname, "updated");
}
////////////////////////////////////////////////////////////
function sendMessage(companyName, action)
////////////////////////////////////////////////////////////
{
var data = {"CompanyName" : companyName, "Action" : action}
callServer("SendMessage", window.messageSent, data);
}
////////////////////////////////////////////////////////////
function messageSent(message)
////////////////////////////////////////////////////////////
{
alert(message);
}
////////////////////////////////////////////////////////////
function callServer(method, callback, data, url)
////////////////////////////////////////////////////////////
{
if (!data)
data = {};
if (!url)
url = (window.location.href.split("?")[0].split("/").pop());
var config = {
type: "POST",
url: url + "/" + method,
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
success : callback,
error: function(xhr){alert(xhr.responseText);}
}
jQuery.ajax(config);
}
</script>
<div id="dbnetgrid1"></div>
[WebMethod]
///////////////////////////////////////////////////////////////
public static string SendMessage(string CompanyName, string Action)
///////////////////////////////////////////////////////////////
{
System.Net.Mail.MailMessage Msg = new System.Net.Mail.MailMessage();
Msg.From = new System.Net.Mail.MailAddress("sender@domain.com");
Msg.To.Add(new System.Net.Mail.MailAddress("recipient@domain.com"));
Msg.Subject = "Supplier " + CompanyName;
Msg.Body = "Supplier " + CompanyName + " " + Action + " at :" + System.DateTime.Now.ToString();
string Message = "";
System.Net.Mail.SmtpClient Smtp = new System.Net.Mail.SmtpClient("localhost");
try
{
Smtp.Send(Msg);
Message = "Notification sent";
}
catch(Exception Ex)
{
Message = "Notification Error ==> " + Ex.Message;
}
return Message;
}