Thursday, January 12, 2012

Calculator with Addition

Here is the calculator. I want to mention that when you do multiplication and division you will have to use a somewhat different pattern. There is only a zero in the session variable when you click the operator. That results in the final answer also equaling zero or infinity. Try to figure out how to do these, if you can and we will look at it again on Tuesday.

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Calculator</title>
    <link href="calculator.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tbody>
    <tr>
    <td colspan="4">
        <asp:TextBox ID="txtDisplay" runat="server"></asp:TextBox></td>
    
    </tr>
    <tr>
    <td>
        <asp:Button ID="Button1" runat="server" Text="7" 
CssClass="buttonstyle" OnClick="InputNumber_Click" /></td>
    <td>
        <asp:Button ID="Button2" runat="server" Text="8" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="Button3" runat="server" Text="9" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="btnAdd" runat="server" Text="+" 
CssClass="buttonstyle" OnClick="Operator_Click"/></td>
    </tr>
    <tr>
    <td>
        <asp:Button ID="Button5" runat="server" Text="4" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="Button6" runat="server" Text="5" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="Button7" runat="server" Text="6" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="btnSubtract" runat="server" Text="-" 
CssClass="buttonstyle" OnClick="Operator_Click" /></td>
    </tr>
    <tr>
    <td>
        <asp:Button ID="Button9" runat="server" Text="1" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="Button10" runat="server" Text="2" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="Button11" runat="server" Text="3" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="btnMult" runat="server" Text="*" 
CssClass="buttonstyle" OnClick="Operator_Click"/></td>
    </tr>
    <tr>
    <td>
        <asp:Button ID="btnDel" runat="server" Text="Del" 
CssClass="buttonstyle"/></td>
    <td>
        <asp:Button ID="Button14" runat="server" Text="0" 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="Button15" runat="server" Text="." 
CssClass="buttonstyle" OnClick="InputNumber_Click"/></td>
    <td>
        <asp:Button ID="btnDiv" runat="server" Text="/" 
CssClass="buttonstyle" OnClick="Operator_Click"/></td>
    </tr>
    <tr>
   
    <td colspan="4">
        <asp:Button ID="btnEqual" runat="server" Text="=" 
CssClass="buttonstyle" OnClick="Operator_Click"/></td>
    </tr>
    </tbody>
    </table>
    </div>
    </form>
</body>
</html>



Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["result"] = 0.0;
        }

    }
    protected void InputNumber_Click(object sender, EventArgs e)
    {
        Button b = (Button)sender;
        txtDisplay.Text += b.Text;
    }
    protected void Operator_Click(object sender, EventArgs e)
    {
        Button b = (Button)sender;

        if (b.ID.Equals("btnAdd"))
        {
            Addition();
            Session["operator"] = "+";
        }
        if(b.ID.Equals("btnEqual"))
        {
            Calculate();
        }
    }

    protected void Addition()
    {
       
        try
        {
            double num = GetNumber();
            double numResult = (double)Session["result"];
            Session["result"] = num + numResult;
            txtDisplay.Text = "";
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }

    }

    protected double GetNumber()
    {
       
        double number =0;
        bool isDouble = double.TryParse(txtDisplay.Text, out number);
        if (isDouble == false)
        {
            txtDisplay.Text = "";
            Exception ex = new Exception("Only enter valid numbers");
            throw ex;
        }
        return number;
    }

    protected void Calculate()
    {
        double number = (double)Session["result"];
        double number2 = GetNumber();
        if (Session["operator"].ToString().Equals("+"))
        {
            txtDisplay.Text = (number + number2).ToString();
        }
    }
}

Calculator.css
body {
}

.buttonstyle
{
    width:50px;
    
}

#txtDisplay
{
    text-align:right;
}

Wednesday, January 11, 2012

SQL Functions

--concatination

Select (Lastname + ', ' + firstname) as [Person Name]
From Person

-- Operators
Select DonationAmount, DonationAmount * .85 as [Charity]
From Donation

Select * From Donation
Select YEAR(DonationDate) as [Year] From Donation
Select MONTH(DonationDate) as [Month] from Donation
Select  Distinct Day(DonationDate) as [Day] from Donation


Select DATEPART(MM,DonationDate) From Donation
Select DatePart(hh,DonationDate) as [Month] from Donation

Select DATEDIFF(DD,'12/31/2011', GETDATE())
Select DateAdd(YY, 5, GETDATE())

Select * from PersonAddress

Select CHARINDEX(Street, ' ') From PersonAddress


Select SUBSTRING(Street, 1, 10) 
From PersonAddress

Select SUBSTRING(Street, 1, charindex(' ', Street)) 
From PersonAddress

Select * From Donation
Select '$' +CAST( DonationAmount as Varchar) as Amount from Donation

Select '(' + SUBSTRING(ContactInfo, 1,3) + ')' 
From PersonContact 
Where ContactTypeKey !=6

Select '$' +CAST(( DonationAmount * .85) as Varchar) as CharityAmount from Donation



Monday, January 9, 2012

SQL SELECT


Use CommunityAssist

Select Lastname, Firstname 
From Person;

Select * From Person

Select lastname as [Last Name], 
Firstname as [First Name]
From Person

--if there are no special characters or spaces
--you don't need brackets
Select lastname Surname, 
Firstname Name
From Person

/*this is a multi line
comment */

Select Distinct PersonKey from Donation
Order by PersonKey Desc

Select * from Donation
Order by donationAmount Desc

Select * from Donation
Order by 3 Desc

Select Top 10 DonationKey, DonationAmount
From Donation
Order by DonationAmount Desc

Select DonationKey, donationAmount
From Donation
Where DonationAmount > 1000

-- > < >= <= != <>

Select * From PersonAddress
Where City='Seattle'

Select * From PersonAddress
Where not City='Seattle'

Select * from Donation
Where DonationDate='2/2/2010'

Select * from Donation
Where DonationDate between '2/2/2010' And '2/6/2010'

Select * From PersonAddress
Where City='Kent' or City='Bellevue'

Select * From PersonContact
Where ContactInfo LIKE '306%'
-- _ for a single character ITC22_ 220 222 224 226

Select * From Donation
Where EmployeeKey in (3, 4, 5)

Select * from PersonAddress
Where Apartment is Not Null

Sunday, January 8, 2012

ITC 222 assignment six

Insert, Update, Delete


Problems


1-5 Insert the following new customer, his vehicle, and the services provided. He is not going to become a registered customer at this time. (This will require multiple insert statements. You will also need to look up the automatically generate keys to use as foreign keys.)

Jay Russell, license BFM349, Ford Fusion, 2011, at the new Tacoma shop. He got an oil change and new windshield wipers.

6. Registered customer 7 has a new email address. Change it to "laura26@yahoo.com" change the password to "moonshine"

7. Change the price of auto service 12 to $110.90

8. Delete AutoserviceDetailID 80 from vehicle service detail.



What I am Looking for


The insert requires some effort. Not only do you have to do multiple insert statements, you also have to look up vales, and the inserts must be done in the correct order. 1through 5 are wort 7 points. The others are worth 1 point each, though they are not without their dangers


To Turn In


Copy the SQL code to a Google doc and share it with spconger@gmail.com

Saturday, January 7, 2012

ITC 222 Assignment Five

Sub Queries




Problems


For each of these problems use subqueries for all parts of the problem, even though joins may make more sense to you.

1. List the name and price of the service with the maximum price.

2. Get a list of the first and last names of every person who is an employee.

3. Get a list of all the employee supervisors.

4. List the name of every person who is not a registered customer.

5. Get the license make and year of every vehicle that has been served. Some may appear more than once. You can use DISTINCT to not show duplicates.

6. Get the same information as in number five but only for those vehicles that have had service 12 completed on them.

7. Now repeat the query above, but include the service name in the select clause. (Remember, no inner joins).

8. Get the service price, the average service price and the difference between the two for every service. Sort them in descending order by service price. (This is one that can only be done with subqueries).



What I am looking for


I want only sub queries. 1 through 6 are worth 1 point each. 7 and 8 are worth 2 points each.


To Turn in


Post the SQL in a Google doc. Share it with spconger@gmail.com

ITC 222 Assignment 4

Joins


Inner Joins

1. Return the names (first and last) and emails of every registered user.

2. Do the same query based on the old style "where" based syntax.

3. List the customer names, the license plate, the vehicle make and year of every registered customer.

4. List the customer name, the license plate, the vehicle make and year and the services provided for the Vehicle service with the ID of 12.

5. List the location names and the names of all the employees that work at those locations.

Cross Joins

6. Do a cross join between Person and registered customer. Use the cross Join syntax.

7. Do a cross join using the older syntax

Outer Joins

8. List the customers people that do not have a registered customer account.

9. List any location names that has never provided a service for any car


What I am looking for

I want to see the SQL that would provide the data to the query. Each one is worth 1 pt. with one point for free for a total of 10 points.


To Turn in

Copy the SQL into a Google doc. Share it with spconger@gmail.com

Thursday, January 5, 2012

Stuf for the first Assignment

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
Inherits="_Default"  Trace="false" ViewStateMode="Enabled"%>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Stuff</h1>
    <asp:DropDownList ID="DropDownList1" runat="server">
        
        </asp:DropDownList>
        <p><asp:Label ID="Label1" runat="server" Text="Enter Name"></asp:Label>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox></p>
        <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
        
    
        <asp:Button ID="btnConfirm" runat="server" Text="Confirm" 
            onclick="btnConfirm_Click" />
        
    
    </div>
    </form>
</body>
</html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] colors = new string[5];
        colors[0] = "Blue";
        colors[1] = "Green";
        colors[2] = "Red";
        colors[3] = "Yellow";
        colors[4] = "Teal";

        if (!IsPostBack)
        {
            DropDownList1.DataSource = colors;
            DropDownList1.DataBind();
        }

        //DropDownList1.Items.Add("Red");
        //DropDownList1.Items.Add("Green");
    }
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        string name = txtName.Text;
        string date = Calendar1.SelectedDate.ToShortDateString();
        string chosenColor = DropDownList1.SelectedItem.ToString();

        //Response.Redirect("Confirmation.aspx?name=" 
        //    + name+"&date="
        //    +date+"&color="+chosenColor);

        Session["name"] = name;
        Session["color"]=chosenColor;
        Session["date"] = date;

        Response.Redirect("Confirmation.aspx");
    }
   
}

Confirmation.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Confirmation.aspx.cs" Inherits="Confirmation" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Confirmation Page</h1>
    </div>
    <asp:Label ID="lblName" runat="server" Text="Label"></asp:Label><br />
    <asp:Label ID="lblColor" runat="server" Text="Label"></asp:Label><br />
    <asp:Label ID="lblDate" runat="server" Text="Label"></asp:Label>


    </form>
</body>
</html>


Confirmation.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Confirmation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //lblColor.Text = Request.QueryString["color"];
        //lblName.Text = Request.QueryString["name"];
        //lblDate.Text = Request.QueryString["date"];
        if (Session["color"] != null)
        {
            lblColor.Text = Session["color"].ToString();
            lblDate.Text = Session["date"].ToString();
            lblName.Text = Session["name"].ToString();
        }
        else
        {
            Response.Redirect("Default.aspx");
        }

        
    }
}