Search This Blog

Tuesday, May 10, 2011

ASP.Net 3.5 with C#/ SQL Server Express - My Summer Project

The SQL Server Express application is still not functioning. Having problems with installation. BUT the ASP.Net/C# goal is progressing nicely. I just finished a chapter where I had to create a shopping cart. Four pages (2 ASP.Net and 2 C# pages), a database, two classes, and multiple images were provided from the author's website. I wrote and debugged the CheckOut.aspx (ASP.Net), CheckOut.aspx.cs (C#), and Customer.cs (Customer Class). I also set up validation and went a step further to provide proper email validation by searching for code on the internet:

ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"

I am using Murach's ASP.Net 3.5 with C# 2008 book. I really enjoy using it. I was struggling with it for awhile but as a result of just finishing a class on C++, C# is a bit similar to C++ and also similar to classic asp, using this book finally clicked with me since the author said that you need to be familiar with C# before starting the book. Leave it to me to do things backwards. : )

I think my next project will involve making a login page or using SQL in a project if I can get away without using the SQL Server I am trying to install. So I will skip around a bit in the book. I will just have to figure it out with the Internet and the two new C# books I bought from Amazon. If stuck, I can always go to Dream In Code for help.

Here are some screen shots of the project: (Click to enlarge)


 
Here is what the Visual Studio 2008 dashboard looks like: (Click to enlarge)
Here is the code for "CheckOut.aspx":
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckOut.aspx.cs" Inherits="CheckOut" %>

<!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">
<head runat="server">
    <title>Check Out</title>
    </head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="Label1" runat="server"
            Text="Please enter the following information:"></asp:Label>
        <br />
       
        <br />
   
        <asp:Label ID="lblFirstName" runat="server" Text="First Name:" Width="110px"
            style="text-align: right"></asp:Label>
&nbsp;<asp:TextBox ID="txtFirstName" runat="server" Width="110px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="txtFirstName" Display="Dynamic"
            ErrorMessage="First Name is a required field.">
        </asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="lblLastName" runat="server" Text="Last Name:" Width="110px"
            style="text-align: right"></asp:Label>
&nbsp;<asp:TextBox ID="txtLastName" runat="server"
            Width="110px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ControlToValidate="txtLastName" Display="Dynamic"
            ErrorMessage="Last Name is a required field."></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="lblEmail" runat="server" Text="Email:" style="text-align: right"
            Width="110px"></asp:Label>
&nbsp;<asp:TextBox ID="txtEmail" runat="server" 
            Width="110px"></asp:TextBox>
&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
            ControlToValidate="txtEmail" Display="Dynamic"
            ErrorMessage="Email is a required field."></asp:RequiredFieldValidator>
&nbsp;<asp:RegularExpressionValidator ID="ValidEmailRegExp" runat="server"
            ControlToValidate="txtEmail" Display="Dynamic"
            ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
            ErrorMessage="Please enter a valid email address"></asp:RegularExpressionValidator>
&nbsp;<br />
        <br />
        <asp:Button ID="btnContinue" runat="server" Text="Continue Shopping"
            Width="166px" onclick="btnContinue_Click" />
&nbsp;<asp:Button ID="btnCancel" runat="server" Text="Cancel" Width="166px"
            onclick="btnCancel_Click" />
        <br />
        <br />
   
    </div>
    </form>
</body>
</html>

 Here is the code for "CheckOut.aspx.cs": (It looks very similar to C++)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class CheckOut : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Order.aspx");
        txtFirstName.Text = "";
        txtLastName.Text = "";
        txtEmail.Text = "";
    }

    protected void btnContinue_Click(object sender, EventArgs e)
    {
        Response.Redirect("Order.aspx");
    }
}

Monday, May 9, 2011

C++ Backward String Program


Backward String 

Write a function that accepts a C-string as an argument and displays its contents backwards. For instance, if the string argument is “Gravity” the function should display “ytivarG”. Demonstrate the function in a program that asks the user to input a string and then passes it to the function. 

Here is the output: (Click to enlarge)
Here is the code:
// Kim Pestana C++, Chapt. 11, Backward String
// Backward String
// Write a function that accepts a C-string as an argument and
// displays its contents backwards. For instance, if the string argument is “Gravity”
// the function should display “ytivarG”. Demonstrate the function in a program
// that asks the user to input a string and then passes it to the function.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstring>

// Not sure if I need all libraries but it can't hurt. :)

using namespace std;


// C-String handling function
void Backward (char *);

int main()
{
// define array for letters in a word entered       
char word[41];

// ask user for input
cout << "This program will display the letters of a word entered in backwards order"
       "follwed by a period." << endl;
cout << "Please enter a word not over 40 letters:" << endl;

// display word entered backwards
cin >> word;

cout << "The entered word displayed in reverse is: " << word << endl;

Backward(word);

cout << endl;

       system("Pause");
       return 0;
}


void Backward (char *sentencePtr)

{

       char *p = sentencePtr;
       while ( *p != '\0' )

             ++p;

       while ( p != sentencePtr )

             cout.put ( *--p );
      

}