Friday, January 16, 2009

Book Suggestion

Once a while I will be including some books that I think are helpful on your way to become a better developer.
Here is the first suggestion.

Oracle PL/SQL Programming, 4th Edition

Product Description
For the past ten years, O'Reilly's "Oracle PL/SQL Programming" has been the bestselling book on PL/SQL, Oracle's powerful procedural language. Packed with examples and helpful recommendations, the book has helped everyone--from novices to experienced developers, and from Oracle Forms developers to database administrators--make the most of PL/SQL.

The fourth edition is a comprehensive update, adding significant new content and extending coverage to include the very latest Oracle version, Oracle Database 10"g" Release 2. It describes such new features as the PL/SQL optimizing compiler, conditional compilation, compile-time warnings, regular expressions, set operators for nested tables, nonsequential collections in FORALL, the programmer-defined quoting mechanism, the ability to backtrace an exception to a line number, a variety of new built-in packages, and support for IEEE 754 compliant floating-point numbers.

The new edition adds brand-new chapters on security (including encryption, row-level security, fine-grained auditing, and application contexts), file, email, and web I/O (including the built-in packages DBMS_OUTPUT, UTL_FILE, UTL_MAIL, UTL_SMTP, and UTL_HTTP) and globalization and localization.

Co-authored by the world's foremost PL/SQL authority, Steven Feuerstein, this classic reference provides language syntax, best practices, and extensive code, ranging from simple examples to complete applications--making it a must-have on your road to PL/SQL mastery. A companion web site contains many more examples and additional technical content for enhanced learning.

Check for unsaved data and display a confirmation message if so

Below id the Link function and the necessary parameters that will make it work:

function ContractBasicsSave(){
    Form1.Command.value = "Save";
    isPostBack = true;
    Form1.submit();
}

var isPostBack = false;
var WarnDiscard = "<%=Proxy1.i18n.FM("WarnDiscardChanges")%>";
var WarnSave = "<%=Proxy1.i18n.FM("WarnSaveChanges")%>";
var WarnDelete = "<%=Proxy1.i18n.FM("WarnDelete")%>";
var ExcludeItems = {"SPANSIZE": "SPANSIZE", "GraphStatus": "GraphStatus" };
function checkChanges(url,cmdSave,cmdNoSave,noprompt) {
    if ((!isPostBack) && IsDirty(ExcludeItems) && (noprompt || confirm(WarnSave))) {
        Form1.action = url;
        
ContractBasicsSave();
        //NavLink(cmdSave, url);
    }
    else {
        //NavLink(cmdNoSave, url);
    }
}

Call the function from the Body OnUnload Event.
<body onunload="javascript:checkChanges('../zExelon/ContractBasics.asp', 'Save')">

Make sure you manage the isPostBack variable. Every time you do a Postback, you need to set it to true so the message does not fire off if you are doing a postback.

Error Messages

} catch (e) { ReportError(e); }

– This displays an error message (with red font color and yellow background) wherever it is placed. You can also call this function right after the transaction hyperlinks by inserting the following code: <%if (saveError) ReportError(saveError)%>

Error message for required field: "Required field have missing values".
You can use the alert window to display this. Required fields have an asterisk (*) beside it (example: * Start Time).

Status Messages

Call the function ReportStatus(s) – this is just a simple formatted Response.Write function.

function ReportStatus(s) {
    Response.Write("<div class=StatusBox>" + s + "</div>");

}

Comparing dates in client-side script


 

You need to convert them to a Date object. You might also need to convert it to IsoDate format.

var myCQAStart = new Date(Form1.tCQAStartDate.value);
    var myCQAStop = new Date(Form1.tCQAStopDate.value);
    var myCQAMin = new Date(IsoDate(Form1.minStartTime.value));
    var myCQAMax = new Date(IsoDate(Form1.maxStopTime.value));

    if (myCQAStart < myCQAMin){

        alert("Start Date comes before than the earliest Start Time.");
        return false;

    }

if (myCQAStop > myCQAMax){

        alert("Stop Date comes after than the latest Stop Time.");
        return false;

    }

Comparing dates in the xsl file (in the SQL statement)

Use the Oracle to_date function. If you are using an ISO date (if you called DateIso() from ccs/common.js), you must use the date format 'YYYY-MM-DD"T"HH24:MI:SS'

AND (CREATETIME = to_date('<xsl:value-of select="@CREATETIME"/>','YYYY-MM-DD"T"HH24:MI:SS'))

Getting the current date

Use DateIso(). This is similar to Now() in ASP. Using DateIso() ensures that you are using the correct date format for Lodestar.

To split the date use:

var dt_array=DateIso().split("T");

var newDate = dt_array[0]+" "+dt_array[1];

Numeric text box

Set the class = “numeric” in your input field.

Looping through an XML object generated by LsdbCommand

The xml object created by the function LsdbCommand is actually an XMLDOM object so you can use the XMLDOM commands to manipulate the object. getElementsByTagName(element) instantiates your Element object from which you can extract the .length (how many times to loop) and also as a repository of your values. Loop through the XML using the .length value then use the Element object to extract your data. In the case below, .getAttribute(attributename) was used to pull the data.

    <!--This is the command we use in Lodestar to extract data from a stored procedure in the XSL file-->
    xmlTable = LsdbCommand("LSDB.sp-get-contractitem",{"UIDCONTRACT":PageParams1.UIDCONTRACT});

<!--Get a hold of the record Element in the XML so know how many times you're looping around it-->
xElement = xmlTable.getElementsByTagName("qrySel");

<!--Using the .length attribute, loop through the XML file -->

for (i = 0; i < xElement.length; i++){

    <!--Get the attribute value by using the .getAttribute function-->

Response.Write("<br>UIDCONTRACTITEM: " + xElement [i].getAttribute("UIDCONTRACTITEM"));

}

Selecting data from a single table without having to write a XSL stored procedure

Use the MetaData function. Specify the table name, the parameter and set it to select a single node. You can use the getAttribute function to extract the value.

    xmlTest = MetaData("LSCMCONTRACTITEM", {"UIDCONTRACTITEM":"124"}, {"LOOKUPS":"NO"}).selectSingleNode("//LSCMCONTRACTITEM");

    Response.Write("<br>UIDCONTRACT: " + xmlTest.getAttribute("UIDCONTRACT"))

Getting data directly from the xml object

You must select a single node to be able to do this.

var xmlItems = LsdbCommand("LSDB.sp-get-contractlistitem", {"UIDEXECONTRLISTITEM":PageParams1.Scenario[i]}).selectSingleNode("qrySel");

Then you can get the data using the getAttribute function by passing the column name.

xmlItems.getAttribute("UIDCONTRACT")

Using the Sort control:

    Attach <html xmlns:v="urn:schemas-microsoft-com:vml"> in the <html> tag.

    Attach <script src="../controls/MultiSorting.js" language="jscript"></script> to the ASP code.

    Attach <link rel="stylesheet" type="text/css" href="../controls/MultiSorting.css"> to the HTML code.

    Attach the following controls:

<input type=hidden name="X_ORDER_BY">

<img src="../controls/images/go_eng.gif" onClick="ShowPlot(this)" style="cursor: hand;"/>

    Attach <%=ProcessXsl(XmlFreeFile('../cm/SortData.xml'), XmlFreeFile('../controls/MultiSorting.xslt'), void 0, {"urn:ls-proxy" : Proxy1})%> at the bottom of the page.

Using the dropdown date input control

Set the input css to class=date
Attach ../controls/lsi18n.css to the HTML code
Attach <%= i18nStyles() %> to the HTML code

Get UserID

var Proxy1 = new Proxy(PageParams1.SessionId);
var UserID = Proxy1.UserId();

Stored Procedures

Cannot use < (less than) or > (greater than) in the SQL statement (for stored procedures) inside the XSL file(procedures.PROCS.xsl) .
Solution:

Use > and <