CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Java

 how can I write this ASP code in JSP

Print topic Send  topic

Author Message
Michelle
Posted: 04/12/2005, 2:38 PM

dim pnref
dim result
dim respmsg
pnref= getParam("PNREF")
result = getParam("RESULT")
respmsg = getParam("RESPMSG")
response.write "<font color = red>" & respmsg & "</font><br>"
if result = 0 then
cn.execute("insert into invoices (member_id, invoice_id) values (" &
Session("UserID") & ", '" & pnref & "')")
cn.execute("insert into purchases (invoice_id, order_id, member_id, item_id,
quantity) select '" & pnref & "', order_id, member_id, item_id, quantity from orders
where member_id = " & Session("UserID"))
response.write "Thank you for shopping with us.<br> For your records, the
reference number for this transcation is:<font color = red>" & pnref &
"</font><br>"
else
response.write "This transaction was not approved.<br> Please adjust your payment
details and try again."
end if
Anton Hinxman
Posted: 04/27/2005, 6:35 AM

Personal choice but this is the way I would approach it.

Note - I am almost retired from coding having found something else which pays better...

Code not compiled or checked.

  
//Event AfterInitialize Action Custom Code .......  
/* -------------------------- *  
 *  write your own code here  *  
 * -------------------------- */  
com.codecharge.components.Page targetPage = e.getPage();  
if(targetPage != null) {  
	HttpServletResponse response = targetPage.getResponse();  
	response.setContentType( "text/html");  
	String pnref = targetPage.getHttpGetParameter("PNREF");  
	String result = targetPage.getHttpGetParameter("RESULT");  
	String respmsg = targetPage.getHttpGetParameter("RESPMSG");  
	PrintWriter printwriter = response.getWriter();  
	printwriter.println("<html>");  
	// For security to html you MUST use StringUtils.toHtml()  
	printwriter.println("<br><br><br><font face=\"Arial\" color = red> "+   
			StringUtils.toHtml(respmsg)+   
			"</font><br>");  
  
	if( result == null ) {  
		printwriter.println(	"Result parameter is missing <br>"+  
					" - please report as programmer error<br>");  
	}  
	else  
	{  
		int resultint = -1;  
		try {  
			resultint = Integer.parseInt(result);  
			if( resultint != 0) {  
				printwriter.println(	"This transaction was not approved.<br>"+   
							"Please adjust your payment details and try again.");  
			}  
		} catch (NumberFormatException nfe) {  
			printwriter.println(	"Result parameter "+ StringUtils.toHtml(result)+ " is not numeric <br>"+  
						" - please report as programmer error<br>");  
		}  
		String uid = Utils.getUserId(targetPage);  
		// If all ok then do the updates...  
		if( uid != null && !"".equals(uid) && resultint == 0 ) {  
			com.codecharge.db.JDBCConnection cn = null;  
			try  
			{  
				String uidSQL = DBTools.toSql( uid, JDBCConnection.TEXT,"YOURDBCON");  
				String pnrefSQL = DBTools.toSql( pnref, JDBCConnection.TEXT,"YOURDBCON");  
				cn = JDBCConnectionFactory.getJDBCConnection("YOURDBCON");  
				// Are you SURE about pnref into invoice_id ???  
				String theUpdateSQL =   
					"insert into invoices ("+  
						"  member_id, invoice_id) "+  
					"values ( "+  
						uidSQL+ ","+ ", "+ pnrefSQL+ ")";  
				CCLogger.getInstance().info(theUpdateSQL);  
				theUpdateSQL =   
					"insert into purchases ("+  
						"invoice_id, order_id, member_id, item_id,quantity)"+  
					" select "+ pnrefSQL+ ", order_id, member_id, item_id, quantity "+  
						"from orders where member_id = "+ uidSQL+ ")";  
				CCLogger.getInstance().info(theUpdateSQL);  
				cn.executeUpdate( theUpdateSQL );  
				printwriter.println(	"Thank you for shopping with us.<br>"+  
							"For your records, the reference number for "+  
							"this transcation is:<font color = red>"+  
							StringUtils.toHtml( pnref )+ "</font><br>";  
			}  
			} catch (Exception anyError) {  
				CCLogger.getInstance().error("Transaction has error:"+ anyError.getMessage());   
				anyError.printStackTrace();  
			} finally {  
				// Rude clean-up JIC...  
				// This is an absolute must for the sake of your connection pool....  
				if(cn instanceof com.codecharge.db.JDBCConnection) {  
					CCLogger.getInstance().info("Rude connection clean-up in 'user transaction'");  
					cn.closeConnection();  
					cn = null;  
				}  
			}  
			// This is an absolute must for the sake of your connection pool....  
			// Close with grace...  
			if(cn instanceof com.codecharge.db.JDBCConnection) {  
				CCLogger.getInstance().info("Proper post 'user transaction' close of connection");  
				cn.closeConnection();  
				cn = null;  
			}  
		}  
	}  
	printwriter.println("</html>");  
	printwriter.flush();  
	printwriter.close();  
}  
  
//End Event AfterInitialize Action Custom Code  

Java is good and robust + Codecharge code I found to be solid.

Regards

Anton Hinxman
eserver221
Posted: 04/27/2005, 6:19 PM

Quote :
I’m interested in this also. Currently I use a blank include page with the business logic classes in the pages event handler - quick and dirty to edit in CCS but static properties and methods are not possible. I have the blank page included in my footer and my footer is in most pages. This gives me a single point of change in the future.

hi, Anton. Would you please show me a sample? I'd appreciate that very much.
Frank
Posted: 05/05/2005, 1:39 PM

Try this

Regards,

Frank

<%

String pnref;

String result;

String respmsg;

String sSQL1;

String sSQL2;

String UserID = session.getAttribute("UserID").toString();

pnref= request.getParameter("PNREF");

result = request.getParameter("RESULT");

respmsg = request.getParameter("RESPMSG");

out.println("<font color = red>" + respmsg + "</font><br>");

if (result == null) {

sSQL1 = "insert into invoices (member_id, invoice_id) values (" +

UserID + ", '" + pnref + "')";

// Execute Query


sSQL2 = "insert into purchases (invoice_id, order_id, member_id, item_id," +

" quantity) select '" + pnref + "', order_id, member_id, item_id, quantity
from " +

" orders where member_id = " + UserID;

// Execute Query

out.println("Thank you for shopping with us.<br> For your records, the" +

" reference number for this transcation is:<font color = red>" + pnref +

"</font><br>");

} else {

out.println("This transaction was not approved.<br> Please adjust your" +

" payment details and try again.");

}

%>

"Michelle" <Michelle@forum.codecharge> wrote in message
news:9425c3fccc3594@news.codecharge.com...
> dim pnref
> dim result
> dim respmsg
> pnref= getParam("PNREF")
> result = getParam("RESULT")
> respmsg = getParam("RESPMSG")
> response.write "<font color = red>" & respmsg & "</font><br>"
> if result = 0 then
> cn.execute("insert into invoices (member_id, invoice_id) values (" &
> Session("UserID") & ", '" & pnref & "')")
> cn.execute("insert into purchases (invoice_id, order_id, member_id,
> item_id,
> quantity) select '" & pnref & "', order_id, member_id, item_id, quantity
> from
> orders
> where member_id = " & Session("UserID"))
> response.write "Thank you for shopping with us.<br> For your records, the
> reference number for this transcation is:<font color = red>" & pnref &
> "</font><br>"
> else
> response.write "This transaction was not approved.<br> Please adjust your
> payment
> details and try again."
> end if
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.