Tuesday, July 20, 2010

Web Page Code

Here is the 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></title>
</head>
<body>
<h1>Make a Donation</h1>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label>
 <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="label3" runat="server" Text="Street"></asp:Label>
 <asp:TextBox ID="txtStreet" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="Apartment"></asp:Label>
 <asp:TextBox ID="txtApartment" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label5" runat="server" Text="City"></asp:Label>
 <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label6" runat="server" Text="State"></asp:Label>
 <asp:TextBox ID="txtState" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label7" runat="server" Text="Zip code"></asp:Label>
 <asp:TextBox ID="txtZip" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label8" runat="server" Text="home phone"></asp:Label>
 <asp:TextBox ID="txtHome" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label9" runat="server" Text="work Phone"></asp:Label>
 <asp:TextBox ID="txtWork" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label10" runat="server" Text="email"></asp:Label>
 <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label11" runat="server" Text="Donation Amount"></asp:Label>
 <asp:TextBox ID="txtDonation" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
<asp:Label
ID="lblalerts" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>

Here is the c# code Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

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

}
protected void Button1_Click(object sender, EventArgs e)
{
//connect to the database
//pass it some command any parameters
//deal with results

SqlConnection connect = new SqlConnection
("Data source=localhost;initial catalog=communityAssist;integrated security=true");

SqlCommand cmd = new SqlCommand();
cmd.Connection = connect;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "donor.usp_RegisterDonor";

cmd.Parameters.AddWithValue("@Lastname", txtLastName.Text);
cmd.Parameters.AddWithValue("@firstname", txtFirstName.Text);
cmd.Parameters.AddWithValue("@Street", txtStreet.Text);
cmd.Parameters.AddWithValue("@Apartment", txtApartment.Text);
cmd.Parameters.AddWithValue("@City", txtCity.Text);
cmd.Parameters.AddWithValue("@State", txtState.Text);
cmd.Parameters.AddWithValue("@Zip", txtZip.Text);
cmd.Parameters.AddWithValue("@DonationAmount", double.Parse(txtDonation.Text));

if (txtHome.Text != "")
{
cmd.Parameters.AddWithValue("@HomePhone", txtHome.Text);
}

if (txtWork.Text != "")
{
cmd.Parameters.AddWithValue("@WorkPhone", txtWork.Text);
}

if (txtEmail.Text != "")
{
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
}

int result;
connect.Open();
result=(int)cmd.ExecuteNonQuery();
connect.Close();



if (result > 0)
{
lblalerts.Text = "Thank you for your donation";
}
else
{
lblalerts.Text = "there are problems with your donation";
}

}
}

No comments:

Post a Comment