100% found this document useful (1 vote)
180 views3 pages

Custom Functions

1. The code checks if a record with the same UID already exists in the AME_LMCP table. If so, it cancels the insert and returns false. 2. If the insert is not cancelled, it checks the final_cat field value and inserts related records into other tables. 3. It also checks for existing records in other tables before inserting to prevent duplicates.

Uploaded by

abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
180 views3 pages

Custom Functions

1. The code checks if a record with the same UID already exists in the AME_LMCP table. If so, it cancels the insert and returns false. 2. If the insert is not cancelled, it checks the final_cat field value and inserts related records into other tables. 3. It also checks for existing records in other tables before inserting to prevent duplicates.

Uploaded by

abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

function Row_Inserting($rsold, &$rsnew) {

// Enter your code here


// To cancel, set return value to FALSE

$MyCount = ew_ExecuteScalar("SELECT COUNT(*) from AME_LMCP where UID=(" .


$rsnew["UID"] . ")");
if ($MyCount !=0){

$this->setFailureMessage("Failed to add the record");


return FALSE;
}
else
return True;
}
-----------------------------------------------------------------------------------
-------------------------
// Row Inserted event
function Row_Inserted($rsold, &$rsnew) {

//echo "Row Inserted"


if ($rsnew["final_cat"] == "RME")
{
$MyResult = ew_Execute(" insert into AME_RMEM (UID,Year) values
('" . $rsnew["UID"] . "','" . $rsnew["AME_YR"] . "')");
$MyResult = ew_Execute(" insert into AME_RMED (UID,Year) values
('" . $rsnew["UID"] . "','" . $rsnew["AME_YR"] . "')");
}
}

--------------other-----------
$sql = "select LMC_Permanent from AME_LMCP where uid=('" . $rsnew["UID"] .
"')";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id_var', $id_var);
$stmt->execute();
if($stmt->fetch()) {
// row found
} else {
// row not found
}
$stmt->closeCursor();

global $conn;
// Get component based on ID_Products
$rs = $conn->Execute("select LMC_Permanent from AME_LMCP where uid=('" .
$rsnew["UID"] . "')");
if ($rs->RecordCount() > 0)
{
$MyResult = ew_Execute("insert into AME_LMCT (UID,Year,Remarks,Shape) values
('" . $rsnew["UID"] . "','" . $rsnew["AME_YR"] . "','" . $rsnew["Remarks"] .
"','" . $rsnew["final_cat"] . "')");
}
}

$query = "SELECT username from my_table where username='bob'";


$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
// row exists. do whatever you would like to do.
}

$Shape= '" . $rsnew["final_cat"] . "';


if ( $Shape!="SHAPE1")
{
$MyResult = ew_Execute("IF NOT EXISTS (select * from AME_LMCP
where uid=('" . $rsnew["UID"] . "')) BEGIN insert into AME_LMCT
(UID,Year,Remarks,Shape) values ('" . $rsnew["UID"] . "','" . $rsnew["AME_YR"] .
"','" . $rsnew["Remarks"] . "','" . $rsnew["final_cat"] . "') END");
}

("
IF NOT EXISTS (select * from AME_LMCP where uid=('" .
$rsnew["UID"] . "'))
BEGIN
insert into AME_LMCT (UID,Year,Remarks,Shape) values ('" .
$rsnew["UID"] . "','" . $rsnew["AME_YR"] . "','" . $rsnew["Remarks"] . "','" .
$rsnew["final_cat"] . "')
");

("
IF NOT EXISTS (select * from AME_LMCP where uid=16010543)
BEGIN
insert into AME_LMCT (UID,Year,Remarks,Shape) values ('" .
$rsnew["UID"] . "','" . $rsnew["AME_YR"] . "','" . $rsnew["Remarks"] . "','" .
$rsnew["final_cat"] . "')
");

$Shape= ($rsnew["final_cat"]);
if ( $Shape=="RME")
{
$MyResult = ew_Execute(" insert into AME_RMEM (UID,Year) values ('" .
$rsnew["UID"] . "','" . $rsnew["AME_YR"] . "','" . $rsnew["ame_dT"] . "','" .
$rsnew["Remarks"] . "','" . $rsnew["final_cat"] . "')");
$MyResult = ew_Execute(" insert into AME_RMED (UID,Year) values ('" .
$rsnew["UID"] . "','" . $rsnew["AME_YR"] . "','" . $rsnew["ame_dT"] . "','" .
$rsnew["Remarks"] . "','" . $rsnew["final_cat"] . "')");

}
$MyResult = ew_Execute(" insert into AME_SHP (UID,Year) values ('" . $rsnew["UID"]
. "','" . $rsnew["AME_YR"] . "','" . $rsnew["ame_dT"] . "','" . $rsnew["Remarks"] .
"','" . $rsnew["final_cat"] . "')");

// Get a field value


// NOTE: Modify your SQL here, replace the table name, field name and the condition
$MyField = ew_ExecuteScalar("SELECT MyField FROM MyTable WHERE XXX");
$limit = ew_ExecuteScalar("SELECT products FROM yourtable WHERE pkg = " .
$rsnew["pkg"]); // assume pkg is your selection
$ri = ew_ExecuteScalar("SELECT COUNT(*) FROm YourTable WHERE ID = " .
$rsnew["ID"]); // assume ID is your ID
if ($ri > $limit) {
$this->CancelMessage = "Exceeded the record";
return FALSE; // cancel the insert/update
} else {
return TRUE;
}

You might also like