<script>
jQuery(document).ready( init )
function init()
{
var dbnetedit1 = new DbNetEdit("dbnetedit1");
with (dbnetedit1)
{
connectionString = "SamplesDatabase"
fromPart = "Products"
bind("onRecordValidate", validateInsert)
setColumnExpressions("ProductName","SupplierID","UnitPrice")
setColumnProperty("ProductName","required", true)
setColumnProperty("UnitPrice","required", true)
setColumnProperty("SupplierID","lookup", "select SupplierID, CompanyName from suppliers")
initialize()
}
}
///////////////////////////////////////////////////////////////
function validateInsert(sender, args)
///////////////////////////////////////////////////////////////
{
if ( sender.mode == "update")
return;
var params = {};
params["ProductName"] = args.parameters["productname"];
var data = sender.executeSingletonQuery("select ProductID from Products where ProductName = @ProductName", params);
if (data )
{
args.message = "A product with this name is already recorded";
args.cancel = true;
}
if ( args.parameters["unitprice"] )
if ( args.parameters["unitprice"] < 5 )
{
args.message = "Unit price cannot be less than 5";
args.columnToHighlight = "unitprice";
args.cancel = true;
}
}
</script>