ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
shangbaby@gmail.com
                   818-235-9779
http://www.shangbaby.net/joomlajoy
?MSSQL  SERVER user stored procedure
?SSRS ¨C Customer Transaction Summary
?HTML Form ¨C The HTML behind it!
?PHP Form Validation ¨C The PHP behind it!
?   This particular piece of code creates a stored procedure. Upon
    execution it initially validates that the customer is linked to
    the account.

?   There are two other validations that has to do with entry of
    negative numbers in the ¡°TransactionAmount¡± field and
    adding an overdraft service charge when there isn?t any funds
    to cover the transaction.
Microsoft SQL
?   USE [PiggyBank]
?   GO
?   /* Object: StoredProcedure [dbo].[WithdrawalODFees] Script Date: 02/24/2011 13:23:09 */
?   SET ANSI_NULLS ON
?   GO
?   SET QUOTED_IDENTIFIER ON
?   GO
?   ---- =============================================
?   ---- Author: Shangz Brown
?   ---- Create date: 02/22/2011
?   ---- Description Withdrawal with overdraft fee generation
?   ---- =============================================
?   CREATE PROCEDURE [dbo].[WithdrawalODFees]
?   --Input and output parameters to create account
?           @CustomerID               int      = null,
?           @AccountID                int      = null,
?           @TransactionAmount        money = null,
?           @TransactionTypeID         int     = null,
?           @NewBalance               money      OUTPUT
?   AS
?   SET XACT_ABORT ON
?   --Validate that @AccountID belongs to the same customer (linked in customer Accounts table)
?                   IF (SELECT CustomerAccountID
?                       FROM CustomerAccount
?                       WHERE AccountID = @AccountID
                      and CustomerID = @CustomerID) is null
?                  BEGIN
?                  raiserror('Account must be linked to the CustomerID entered', 11, 1)
?                  RETURN
?                  END
This part of the T-SQL stored procedure code blocks
activity on closed accounts that may be entered by users
?   --Block Transactions on inactive accounts.
?             IF (Select A.AccountID
?                 FROM Account AS A
?                 JOIN CustomerAccount AS CA
?                 ON A.AccountID=CA.AccountID
?                 WHERE AccountStatusID=2
?                 AND CA.CustomerID=@CustomerID
?                 AND A.AccountID =@AccountID) =@AccountID
?             BEGIN
?                      raiserror('Transactions are not allowed on inactive accounts', 11, 1)
?           RETURN
?             END
?   --D/E CHECK: Prevent negative money amounts to be entered in the Transaction Amount parameter.
?   --Logic: You can not make a deposit via the withdraw proc.
?         IF @TransactionAmount <=0
?             BEGIN
?                     raiserror('Transaction Amount can not be a negative number.', 11, 1)
?            RETURN
?            END
?   BEGIN
?   -- SET NOCOUNT ON added to prevent extra result sets from
?   -- interfering with SELECT statements.
?   SET NOCOUNT ON;
?   -- Encapsulate procedure in a try catch block
?         BEGIN TRY
?         BEGIN TRAN
?   --make insert conditional
?   -- If TA >CB, AND test if EXIST [OD] is true, if TRUE proceed.
?          IF @TransactionAmount >
?               (SELECT CurrentBalance
?                 FROM Account
?                 WHERE AccountID =@AccountID)
?                 AND exists (SELECT AccountID
?                FROM Account
?                 WHERE OverDraftAccountID is not null)
?           SET @NewBalance =
?              (SELECT CurrentBalance
?               FROM Account
?               WHERE AccountID = @AccountID) - (@TransactionAmount+10)
?          -- record transaction.
?   INSERT INTO [PiggyBank].[dbo].[Transactions]
?            ([AccountID]
?            ,[TransactionTypeID]
?            ,[CustomerID]
?            ,[TransactionDate]
?            ,[TransactionAmount]
?            ,[NewBalance])
?
?   VALUES
?          (@AccountID
?          ,@TransactionTypeID
?          ,@CustomerID
?          ,GETDATE()
?          ,@TransactionAmount
?          ,@NewBalance)
?                   UPDATE dbo.Account
?                   SET CurrentBalance =@NewBalance
?                   WHERE AccountID = @AccountID
?           Print 'Not enough funds in main account to cover transaction.
?           Transaction amount + $10 service fee HAS BEEN debited from this account'
?         COMMIT TRAN
?         END TRY
?   --Catch errors
?      BEGIN CATCH
?   --Rollback transaction
?           IF @@trancount > 0
?           ROLLBACK TRAN
?           DECLARE       @ErrorMessage      NVARCHAR(4000),
?                         @ErrorState        INT
?           SELECT        @ErrorMessage = ERROR_MESSAGE(),
?                         @ErrorState      = ERROR_STATE()
?           RAISERROR ( @ErrorMessage, 11, @ErrorState)
?           RETURN
?      END CATCH
?   END
?   GO
SSRS ¨C SQL Server Reporting Services ¨C This is a report I created using Visual Studio
2008. The source was a stored procedure in my PiggyBank project. I wanted to create a
statement listing the transactions along with customer name and address. The result
follows on the next slide.
Shangz R Brown Presentation
?   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
     <metahttp-equiv="content-type" content="text/html; charset=iso-8859-1" />
     <title>Simple HTML Form</title>
    </head>
    <body>

    <form action="handle_form.php" method="post">

     <fieldset><legend>Enter your information in the form below:</legend>

     <p> <b>Name:</b>
?         <input type="text" name="name" size="20¡± maxlength="40" />
?    </p>
     <p> <b> Email Address: </b>
?        <input type="text" name="email" size="40¡° maxlength="60" />
?    </p>
     <p> <b>Gender:</b>
?        <input type="radio" name="gender" value="M" />Male
?        <input type="radio" name="gender" value="F" /> Female
?    </p>
     <p> <b>Age:</b>
         <select name="age">
         <option value="0-29"> Under 30            </option>
         <option value="30-60"> Between 30 and 60 </option>
         <option value="60+"> Over 60             </option>
         </select>
?    </p>
     <p> <b>Comments:</b>
?        <textarea name="comments" rows="3" cols="40"></textarea>
?    </p>
     </fieldset>
     <div align="center"><input type="submit" name="submit" value="Submit My Information" />
     </div>
    </form>
    </body>
?   <html>
?   <head>
?    <title>PHP Test</title>
?   </head>
?   <body>
?   <?php # handle_form.php
?   // Create a shorthand for the form data.
?   $name                   = $_REQUEST['name'];
?   $email                  = $_REQUEST['email'];
?   $comments               = $_REQUEST['comments'];
?   $age                    = $_REQUEST['age'];
?   $gender                 = $_REQUEST['gender'];
?   //Validate the name and combat Magic Quotes, if necessary.
?   if (!empty($_REQUEST['name']))
?   { $name = stripslashes($_REQUEST['name']);
?   } else {$name = NULL; echo ? <p><font color ="red">You forgot to enter your
    name!</font></p>';
?   }
?   //Validate the email address.
?   if (!empty($_REQUEST['email'])) {
?         $email = $_REQUEST['email'];
?   } else {
?         $email = NULL;
?   echo '<p><font color="red"> You forgot to enter your email address! </font></p>';
?   }
?   //*Validate the comments and combat Magic Quotes, if necessary*//
?   if ( !empty($_REQUEST['comments?])) {
?   $comments = stripslashes($_REQUEST['comments?]);
?   } else { $comments = NULL;
?   echo '<p><font color ="red">What? Nothing to say! You forgot to leave some comments! <font/>
?           </p> ';
?   }
?   if (isset($_REQUEST['gender?])) {
?      $gender = $_REQUEST['gender'];
?   if ($gender == 'M') {
?         $message = '<p><b>Good day, Sir!</b></p>';
?      } elseif ($'gender == 'F?) {
?         $message = '<p><b>Good day, Madam!</b> </p>';
?      } else {        // Unacceptable value.
?         $message=NULL;
?         echo '<p><font color="red">Gender should be either male or female!</font></p>';
?      }
?   } else {           //gender is not set.
?      $gender = NULL;
?      echo ? <p><font color="red">You forgot to select your gender! </font></p>';
?   }
?   // If everything is okay, print the message.
?   if ($name && $email && $gender && $comments) {
?   echo '<p>Thank you <b>$name</b> for the following comments: <br/>
?        <tt>$comments</tt> </p>';
?        echo '<p> We will reply to you at <i>$email</i></p> n';
?        echo $message; // From the $gender conditional.
?   } else {              // One form element was not filled out properly.
?        echo ?<p><font color="red">Please go back and fill out the form again.</font></p>';
?   }
?   ?>
?   </body>
?   </html>

More Related Content

What's hot (20)

PDF
Web 6 | JavaScript DOM
Mohammad Imam Hossain
?
PDF
Taming forms with React
GreeceJS
?
PDF
Candies for everybody - Meet Magento Italia 2015
Alberto L¨®pez Mart¨ªn
?
PDF
Alberto L¨®pez: Candies for everybody: hacking from 9 a.m. to 6 p.m.
Meet Magento Italy
?
PDF
Rapid Prototyping with PEAR
Markus Wolff
?
KEY
Who Needs Ruby When You've Got CodeIgniter
ciconf
?
PPTX
Frank Rodenbaugh Portfolio
FrankRodenbaugh
?
PDF
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad
?
DOCX
Tony Vitabile .Net Portfolio
vitabile
?
PPT
Library Website
gholtron
?
PDF
Refactoring using Codeception
Jeroen van Dijk
?
PPT
Os Nixon
oscon2007
?
PDF
Web 5 | JavaScript Events
Mohammad Imam Hossain
?
PPT
Framework
Nguyen Linh
?
PDF
Order to cash cycle
Maheedhar Kambham
?
PDF
Javascript
orestJump
?
PDF
Ruby - Design patterns tdc2011
Rafael Felix da Silva
?
PDF
TYCS Visual Basic Practicals
yogita kachve
?
ODP
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Jeremy Kendall
?
PPT
Form validation server side
Mudasir Syed
?
Web 6 | JavaScript DOM
Mohammad Imam Hossain
?
Taming forms with React
GreeceJS
?
Candies for everybody - Meet Magento Italia 2015
Alberto L¨®pez Mart¨ªn
?
Alberto L¨®pez: Candies for everybody: hacking from 9 a.m. to 6 p.m.
Meet Magento Italy
?
Rapid Prototyping with PEAR
Markus Wolff
?
Who Needs Ruby When You've Got CodeIgniter
ciconf
?
Frank Rodenbaugh Portfolio
FrankRodenbaugh
?
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad
?
Tony Vitabile .Net Portfolio
vitabile
?
Library Website
gholtron
?
Refactoring using Codeception
Jeroen van Dijk
?
Os Nixon
oscon2007
?
Web 5 | JavaScript Events
Mohammad Imam Hossain
?
Framework
Nguyen Linh
?
Order to cash cycle
Maheedhar Kambham
?
Javascript
orestJump
?
Ruby - Design patterns tdc2011
Rafael Felix da Silva
?
TYCS Visual Basic Practicals
yogita kachve
?
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Jeremy Kendall
?
Form validation server side
Mudasir Syed
?

Viewers also liked (7)

PDF
A software factory in a box
Silvio Gulizia
?
PDF
Stored Procedure
NidiaRamirez07
?
PPTX
Advance Sql Server Store procedure Presentation
Amin Uddin
?
PPTX
Stored procedures with cursor
baabtra.com - No. 1 supplier of quality freshers
?
PPTX
PHP and database functionality
Sayed Ahmed
?
PPTX
Pert 3. stored_procedure
Abrianto Nugraha
?
PPTX
Stored procedure tunning
Virendra Yaduvanshi
?
A software factory in a box
Silvio Gulizia
?
Stored Procedure
NidiaRamirez07
?
Advance Sql Server Store procedure Presentation
Amin Uddin
?
PHP and database functionality
Sayed Ahmed
?
Pert 3. stored_procedure
Abrianto Nugraha
?
Stored procedure tunning
Virendra Yaduvanshi
?
Ad

Similar to Shangz R Brown Presentation (20)

PPT
Presentation Paul
Paul Glaeser
?
DOC
Marcus Portfolio
marobertson22
?
PDF
Banking Database
Ashwin Dinoriya
?
PPT
My Portfolio
guest0ff0f54d
?
PPT
My Portfolio
dmcglasson
?
PPTX
Marcus Matthews
MarcusMatthews38
?
PPTX
Dependency injection - the right way
Thibaud Desodt
?
PDF
Payments On Rails
E-xact Transactions
?
PDF
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
?
PDF
Serverless Functions and Vue.js
Sarah Drasner
?
DOCX
WEB DESIGN PRACTICLE bca
YashKoli22
?
DOCX
YASH HTML CODES
YashKoli22
?
DOCX
YASH HTML CODE
YashKoli22
?
DOCX
Kyoto sfdg meetup3_samplecode__forsharing
ÓÑËà СҰ
?
PDF
Rajeev oops 2nd march
Rajeev Sharan
?
PDF
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
JUSTSTYLISH3B2MOHALI
?
PDF
This what Im suppose to do and this is what I have so far.In thi.pdf
kavithaarp
?
PDF
#include iostream #include BankAccountClass.cpp #include .pdf
ANJANEYAINTERIOURGAL
?
PDF
main.cpp #include iostream #include iomanip #include fs.pdf
arwholesalelors
?
PDF
Ruby on Rails For Java Programmers
elliando dias
?
Presentation Paul
Paul Glaeser
?
Marcus Portfolio
marobertson22
?
Banking Database
Ashwin Dinoriya
?
My Portfolio
guest0ff0f54d
?
My Portfolio
dmcglasson
?
Marcus Matthews
MarcusMatthews38
?
Dependency injection - the right way
Thibaud Desodt
?
Payments On Rails
E-xact Transactions
?
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
?
Serverless Functions and Vue.js
Sarah Drasner
?
WEB DESIGN PRACTICLE bca
YashKoli22
?
YASH HTML CODES
YashKoli22
?
YASH HTML CODE
YashKoli22
?
Kyoto sfdg meetup3_samplecode__forsharing
ÓÑËà СҰ
?
Rajeev oops 2nd march
Rajeev Sharan
?
C++ Bank Account Error Fix, full code. I am using Dev-C++ to Compile.pdf
JUSTSTYLISH3B2MOHALI
?
This what Im suppose to do and this is what I have so far.In thi.pdf
kavithaarp
?
#include iostream #include BankAccountClass.cpp #include .pdf
ANJANEYAINTERIOURGAL
?
main.cpp #include iostream #include iomanip #include fs.pdf
arwholesalelors
?
Ruby on Rails For Java Programmers
elliando dias
?
Ad

More from shangbaby (6)

XLS
Shangz Brown Excel Sample
shangbaby
?
XLSX
Northwind Sales Contest Analysis
shangbaby
?
XLSX
Loan Interest Calculation
shangbaby
?
XLSX
Decision Analysis
shangbaby
?
DOCX
Brown Expository Essay
shangbaby
?
DOC
Cover Letter Only040511
shangbaby
?
Shangz Brown Excel Sample
shangbaby
?
Northwind Sales Contest Analysis
shangbaby
?
Loan Interest Calculation
shangbaby
?
Decision Analysis
shangbaby
?
Brown Expository Essay
shangbaby
?
Cover Letter Only040511
shangbaby
?

Shangz R Brown Presentation

  • 1. shangbaby@gmail.com 818-235-9779 http://www.shangbaby.net/joomlajoy
  • 2. ?MSSQL SERVER user stored procedure ?SSRS ¨C Customer Transaction Summary ?HTML Form ¨C The HTML behind it! ?PHP Form Validation ¨C The PHP behind it!
  • 3. ? This particular piece of code creates a stored procedure. Upon execution it initially validates that the customer is linked to the account. ? There are two other validations that has to do with entry of negative numbers in the ¡°TransactionAmount¡± field and adding an overdraft service charge when there isn?t any funds to cover the transaction.
  • 4. Microsoft SQL ? USE [PiggyBank] ? GO ? /* Object: StoredProcedure [dbo].[WithdrawalODFees] Script Date: 02/24/2011 13:23:09 */ ? SET ANSI_NULLS ON ? GO ? SET QUOTED_IDENTIFIER ON ? GO ? ---- ============================================= ? ---- Author: Shangz Brown ? ---- Create date: 02/22/2011 ? ---- Description Withdrawal with overdraft fee generation ? ---- ============================================= ? CREATE PROCEDURE [dbo].[WithdrawalODFees] ? --Input and output parameters to create account ? @CustomerID int = null, ? @AccountID int = null, ? @TransactionAmount money = null, ? @TransactionTypeID int = null, ? @NewBalance money OUTPUT ? AS ? SET XACT_ABORT ON ? --Validate that @AccountID belongs to the same customer (linked in customer Accounts table) ? IF (SELECT CustomerAccountID ? FROM CustomerAccount ? WHERE AccountID = @AccountID and CustomerID = @CustomerID) is null ? BEGIN ? raiserror('Account must be linked to the CustomerID entered', 11, 1) ? RETURN ? END
  • 5. This part of the T-SQL stored procedure code blocks activity on closed accounts that may be entered by users ? --Block Transactions on inactive accounts. ? IF (Select A.AccountID ? FROM Account AS A ? JOIN CustomerAccount AS CA ? ON A.AccountID=CA.AccountID ? WHERE AccountStatusID=2 ? AND CA.CustomerID=@CustomerID ? AND A.AccountID =@AccountID) =@AccountID ? BEGIN ? raiserror('Transactions are not allowed on inactive accounts', 11, 1) ? RETURN ? END ? --D/E CHECK: Prevent negative money amounts to be entered in the Transaction Amount parameter. ? --Logic: You can not make a deposit via the withdraw proc. ? IF @TransactionAmount <=0 ? BEGIN ? raiserror('Transaction Amount can not be a negative number.', 11, 1) ? RETURN ? END ? BEGIN ? -- SET NOCOUNT ON added to prevent extra result sets from ? -- interfering with SELECT statements. ? SET NOCOUNT ON;
  • 6. ? -- Encapsulate procedure in a try catch block ? BEGIN TRY ? BEGIN TRAN ? --make insert conditional ? -- If TA >CB, AND test if EXIST [OD] is true, if TRUE proceed. ? IF @TransactionAmount > ? (SELECT CurrentBalance ? FROM Account ? WHERE AccountID =@AccountID) ? AND exists (SELECT AccountID ? FROM Account ? WHERE OverDraftAccountID is not null) ? SET @NewBalance = ? (SELECT CurrentBalance ? FROM Account ? WHERE AccountID = @AccountID) - (@TransactionAmount+10) ? -- record transaction. ? INSERT INTO [PiggyBank].[dbo].[Transactions] ? ([AccountID] ? ,[TransactionTypeID] ? ,[CustomerID] ? ,[TransactionDate] ? ,[TransactionAmount] ? ,[NewBalance]) ?
  • 7. ? VALUES ? (@AccountID ? ,@TransactionTypeID ? ,@CustomerID ? ,GETDATE() ? ,@TransactionAmount ? ,@NewBalance) ? UPDATE dbo.Account ? SET CurrentBalance =@NewBalance ? WHERE AccountID = @AccountID ? Print 'Not enough funds in main account to cover transaction. ? Transaction amount + $10 service fee HAS BEEN debited from this account' ? COMMIT TRAN ? END TRY ? --Catch errors ? BEGIN CATCH ? --Rollback transaction ? IF @@trancount > 0 ? ROLLBACK TRAN ? DECLARE @ErrorMessage NVARCHAR(4000), ? @ErrorState INT ? SELECT @ErrorMessage = ERROR_MESSAGE(), ? @ErrorState = ERROR_STATE() ? RAISERROR ( @ErrorMessage, 11, @ErrorState) ? RETURN ? END CATCH ? END ? GO
  • 8. SSRS ¨C SQL Server Reporting Services ¨C This is a report I created using Visual Studio 2008. The source was a stored procedure in my PiggyBank project. I wanted to create a statement listing the transactions along with customer name and address. The result follows on the next slide.
  • 10. ? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <metahttp-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Simple HTML Form</title> </head> <body> <form action="handle_form.php" method="post"> <fieldset><legend>Enter your information in the form below:</legend> <p> <b>Name:</b> ? <input type="text" name="name" size="20¡± maxlength="40" /> ? </p> <p> <b> Email Address: </b> ? <input type="text" name="email" size="40¡° maxlength="60" /> ? </p> <p> <b>Gender:</b> ? <input type="radio" name="gender" value="M" />Male ? <input type="radio" name="gender" value="F" /> Female ? </p> <p> <b>Age:</b> <select name="age"> <option value="0-29"> Under 30 </option> <option value="30-60"> Between 30 and 60 </option> <option value="60+"> Over 60 </option> </select> ? </p> <p> <b>Comments:</b> ? <textarea name="comments" rows="3" cols="40"></textarea> ? </p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit My Information" /> </div> </form> </body>
  • 11. ? <html> ? <head> ? <title>PHP Test</title> ? </head> ? <body> ? <?php # handle_form.php ? // Create a shorthand for the form data. ? $name = $_REQUEST['name']; ? $email = $_REQUEST['email']; ? $comments = $_REQUEST['comments']; ? $age = $_REQUEST['age']; ? $gender = $_REQUEST['gender']; ? //Validate the name and combat Magic Quotes, if necessary. ? if (!empty($_REQUEST['name'])) ? { $name = stripslashes($_REQUEST['name']); ? } else {$name = NULL; echo ? <p><font color ="red">You forgot to enter your name!</font></p>'; ? } ? //Validate the email address. ? if (!empty($_REQUEST['email'])) { ? $email = $_REQUEST['email']; ? } else { ? $email = NULL; ? echo '<p><font color="red"> You forgot to enter your email address! </font></p>'; ? }
  • 12. ? //*Validate the comments and combat Magic Quotes, if necessary*// ? if ( !empty($_REQUEST['comments?])) { ? $comments = stripslashes($_REQUEST['comments?]); ? } else { $comments = NULL; ? echo '<p><font color ="red">What? Nothing to say! You forgot to leave some comments! <font/> ? </p> '; ? } ? if (isset($_REQUEST['gender?])) { ? $gender = $_REQUEST['gender']; ? if ($gender == 'M') { ? $message = '<p><b>Good day, Sir!</b></p>'; ? } elseif ($'gender == 'F?) { ? $message = '<p><b>Good day, Madam!</b> </p>'; ? } else { // Unacceptable value. ? $message=NULL; ? echo '<p><font color="red">Gender should be either male or female!</font></p>'; ? } ? } else { //gender is not set. ? $gender = NULL; ? echo ? <p><font color="red">You forgot to select your gender! </font></p>'; ? }
  • 13. ? // If everything is okay, print the message. ? if ($name && $email && $gender && $comments) { ? echo '<p>Thank you <b>$name</b> for the following comments: <br/> ? <tt>$comments</tt> </p>'; ? echo '<p> We will reply to you at <i>$email</i></p> n'; ? echo $message; // From the $gender conditional. ? } else { // One form element was not filled out properly. ? echo ?<p><font color="red">Please go back and fill out the form again.</font></p>'; ? } ? ?> ? </body> ? </html>