Difference between revisions of "DD Class12"

esse quam videri
Jump to: navigation, search
(Logon the Microsoft way)
(HomeWORK)
Line 1,129: Line 1,129:
 
</xml>
 
</xml>
  
==HomeWORK==
+
==HomeWork==
  
 
Final Proposal
 
Final Proposal
 +
 +
Final Website proposal. Due 11/29.
 +
Final Proposal
 +
 +
Write a short requirements document (website) that explains
 +
 +
# Rationale: for website design or introduction of product features
 +
# Audience: Description of target audience and segments for new website areas
 +
# Requirements Summary: Key Areas and Features elaborate on requirements above
 +
# Design Documents: Site Map (hand drawn, word doc, xml visio, paper napkin) and Data Diagram (sql 2008 diagram screen shot)
 +
 +
Final Requirements
 +
 +
The final website should show off all of your new .NET skills. I'll leave the idea and the content of the website up to you. Good proposals might be... An anonymous cheese rating website (similar) to midterm but using SQL server as the persistence layer. It would allow ratings for cheese from varios regions then show the most popular cheese by region.
 +
 +
* Use Web Forms for user interaction
 +
* Use State (sessions, application, viewstate)
 +
* Use Database (I can help you design your db if you can't do this) with either SQLDataSource Direct ADO or LINQDataSource
 +
 +
[http://brookfield.rice.iit.edu/jmeyers/463/classsource/CheeseProp.aspx Sample Cheese Poposal]

Revision as of 03:47, 14 November 2011


Authentcation

Authentication Discuss Methods and problems

Methods

  • Windows
  • Passport
  • Forms

The authentication method is set in the root web.config <xml> <authentication mode="Forms">

     <forms loginUrl="logon.aspx" 
       timeout="20" path="/" 
       protection="All">
     </forms>

</authentication> </xml>

We will be using a small section of the .net provider model.S


Logon Using the tables we made last week

You can use the Authorization Section of web.config to protect file or a directory. You can have more than one web.config in a project also. You can have one for each folder. The web.config setting inherit from the parent folder and most section can be overridden. Here is an example of a small web.config that protects a folder call admin with the .net authentication mechanism.

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/Logon/Web.config

Main web.config add the following to the system.web section <xml> <system.web>

    <authentication mode="Forms">

<forms loginUrl="classsource/logon/logon.aspx" name="adAuthCookie" timeout="20" path="/" protection="All"> </forms>

    </authentication>
   </system.web>

</xml>

Now any link to the admin folder

http://iam.colum.edu/dd/classsource/logon/admin/

should redirect to the logon page

Logon Page

http://iam.colum.edu/dd/classsource/Logon/Logon.aspx - source http://iam.colum.edu/dd/gbrowser.php?file=/classsource/Logon/Logon.aspx.cs

Add a New user page http://iam.colum.edu/dd/classsource/Logon/CreateAccount.aspx -source http://iam.colum.edu/dd/gbrowser.php?file=/classsource/Logon/CreateAccount.aspx.cs

Admin Page http://iam.colum.edu/dd/classsource/Logon/Admin/Default.aspx - source http://iam.colum.edu/dd/gbrowser.php?file=/classsource/Logon/Admin/Default.aspx.cs

Logon the Microsoft way

Primary Keys

The candidate key selected as being most important for identifying a body of information (an entity, object or record).

Normalization

Normal Forms

First Normal

Form eliminates repeating groups by putting each into a separate table and connecting them with a one-to-many relationship.

Data Relationships

Not Following First Normal Form Repeating Groups

Blog1

BlogID BlogText recCreationDate Mood
1 Blog1 03/30/03 Happy
2 Blog2 03/30/03 Happy
3 Blog3 03/30/03 Sad
4 Blog4 03/30/03 Happy
5 Blog4 03/30/03 Mad

Tables that Follow First normal form

Blog2

BlogID BlogText recCreationDate MoodID
1 Blog1 03/30/03 1
2 Blog2 03/30/03 1
3 Blog3 03/30/03 2
4 Blog4 03/30/03 1
5 Blog4 03/30/03 3

Mood

MoodID MoodName
1 Happy
2 Sad
3 Mad
4 Afraid

1NF also

Removes multiple column with the same type of data

Books Not Normal

Books

Author Title_01 Pages_01 Title_02 Pages_02 Title_03 Pages_03
Michael Allen Dymmoch The Man Who Understood Cats 256 White Tiger 320
Joseph Cancellaro Exploring Sound Design for Interactive Media 272
In Class Build Blogs Table and Normalize Books Table


http://en.wikipedia.org/wiki/First_normal_form

ERD

http://en.wikipedia.org/wiki/Entity-relationship_model

tools

Views

UserTest

UserID UserName LastLogon
1 jmeyers 3/30/03
2 bgates 4/1/03
3 sjobs 4/2/03
4 ltorvalds 4/3/03


EmailTest

EmailID UserID EmailAddress Active displayEmail
1 1 jeff@interactive.colum.edu 1 0
2 1 only_a_test@hotmail.com 0 0
3 2 bgates@microsoft.com 1 0

[INNER] JOIN

The INNER JOIN returns all rows from both tables where there is a match. If there are rows in User that do not have matches in Email, those rows will not be listed.

-- ANSI Style <sql> SELECT u.UserID, u.UserName, u.LastLogon, e.EmailAddress, e.active, e.displayEmail FROM UserTest u JOIN EmailTest e ON e.UserID = u.UserID </sql>

--Theta style <sql> SELECT u.UserID, u.UserName, u.LastLogon, e.EmailAddress, e.active, e.displayEmail FROM UserTest u, EmailTest e WHERE e.UserID = u.UserID </sql>

results

UserID      UserName            LastLogon                     EmailAddress                     active displayEmail 
----------- ------------------- ----------------------------- -------------------------------- ------ ------------ 
1           jmeyers             2003-03-30 00:00:00.000       jeff@interactive.colum.edu       1      0
1           jmeyers             2003-03-30 00:00:00.000       only_a_test@hotmail.com          0      0
2           bgates              2003-04-01 00:00:00.000       bgates@microsoft.com             1      0

(3 row(s) affected)

LEFT [OUTER] JOIN

The LEFT JOIN returns all the rows from the first table (User), even if there are no matches in the second table (Email). If there are rows in User that do not have matches in Email, those rows also will be listed.

<sql> SELECT u.UserID, u.UserName, u.LastLogon, e.EmailAddress, e.active, e.displayEmail FROM UserTest u LEFT JOIN EmailTest e ON e.UserID = u.UserID </sql>

UserID      UserName     LastLogon                 EmailAddress                 active displayEmail 
----------- ------------ ------------------------- ---------------------------- ------ ------------ 
1           jmeyers      2003-03-30 00:00:00.000   jeff@interactive.colum.edu   1      0
1           jmeyers      2003-03-30 00:00:00.000   only_a_test@hotmail.com      0      0
2           bgates       2003-04-01 00:00:00.000   bgates@microsoft.com         1      0
3           sjobs        2003-04-02 00:00:00.000   NULL                         NULL   NULL
4           ltorvalds    2003-04-03 00:00:00.000   NULL                         NULL   NULL

(5 row(s) affected)

RIGHT [OUTER] JOIN

The RIGHT JOIN returns all the rows from the second table (Email), even if there are no matches in the first table (User). If there had been any rows in Email that did not have matches in User, those rows also would have been listed.

<sql> SELECT u.UserID, u.UserName, u.LastLogon, e.EmailAddress, e.active, e.displayEmail FROM UserTest u RIGHT JOIN EmailTest e ON e.UserID = u.UserID </sql>

results

UserID      UserName            LastLogon                     EmailAddress                     active displayEmail 
----------- ------------------- ----------------------------- -------------------------------- ------ ------------ 
1           jmeyers             2003-03-30 00:00:00.000       jeff@interactive.colum.edu       1      0
1           jmeyers             2003-03-30 00:00:00.000       only_a_test@hotmail.com          0      0
2           bgates              2003-04-01 00:00:00.000       bgates@microsoft.com             1      0

(3 row(s) affected)

Making views in enterprise manager is easy. Just add the tables you want to join and click. It does all the typing for you.


Review First Normal Form

Let build the example for the homework.

Build Interface to GameDB

Games

GameTitle GameGenre DeveloperName Platform(s) Year DeveloperWebsite GameWebsite
Quake1 FPS id Dos 1996 http://www.idsoftware.com/ http://www.idsoftware.com/games/quake/quake/
Diablo RPG Blizzard Windows 95 1996 http://www.blizzard.com/ http://www.blizzard.com/diablo/
SimCity Sim Interplay Dos 1993 http://www.interplay.com/ http://www.maxis.com/

Tables Games, Developers, Websites, Platforms?

Build Views

Nesting Data Bound Controls

nesting controls

Datasource Controls can probably handle up to 70% of your data binding needs but they do have drawbacks. Consider the cheese database which uses an SQL view to join Cheese with Region, Consistency, and MilkType. Of course SQL view don't support updating and can lead to some bad data binding. we can fix a few of these problem with stored procedures.

Simple filter Demo in class

GridView Details View Master Child Relationship


http://iam.colum.edu/dd/classsource/data/CheeseDataBindingFull.aspx source

Stored Procedures

http://iam.colum.edu/dd/classsource/data/sproc/sprocADO.aspx

Cheese browser assignment

Make a creative cheese browser from that tables in you db. Use a view to join that data from multiple tables..

Here's and example of a simple cheese shop browser app.

http://iam.colum.edu/dd/classsource/class8/CheeseShop/CheeseShop1.aspx

Homework

Normalize these tables. Make a UML Drawing for both tables.

Games

GameTitle GameGenre DeveloperName Platform(s) Year DeveloperWebsite GameWebsite
Quake1 FPS id Dos 1996 http://www.idsoftware.com/ http://www.idsoftware.com/games/quake/quake/
Diablo RPG Blizzard Windows 95 1996 http://www.blizzard.com/ http://www.blizzard.com/diablo/
SimCity Sim Interplay Dos 1993 http://www.interplay.com/ http://www.maxis.com/

Cheeses

CheeseName CheeseDescription RegionName Consistency MilkType
Argentinian Reggianito The vast grazing pastures of Argentina revealed themselves to be ideal for immigrant Italians.. Hard Argentina Goats Milk
Feta Feta is made in a traditional manner by a small family dairy in central Greece... Crumbly Greek Mix of Milks
Cheddar The most widely purchased and eaten cheese in the world. Cheddar cheeses were originally made in England, however today they are manufactured in many countries all over the world. Semi-Hard England Cows Milk

Build a blog interface to the blog tables we built in class. The blog interface requires

  • An insert blog page. Don't worry about user names or authentications this is a very public blog more like a message board.
  • A blogroll display page. Be careful which control you use to display the data.

Extra Credit is an edit or delete page.

READ BDD Chapter 4 again Chapter 5

READ BAD Chapter 8

Examples

http://iam.colum.edu/dd/classsource/Data/GridAndDetails.aspx

http://iam.colum.edu/dd/classsource/Data/GridDataBound.aspx

http://iam.colum.edu/dd/classsource/Data/GridDetails.aspx

http://iam.colum.edu/dd/classsource/Data/GridEdit.aspx

http://iam.colum.edu/dd/classsource/Data/GridSelect.aspx

http://iam.colum.edu/dd/classsource/Data/GridSelectTheme.aspx

http://iam.colum.edu/dd/classsource/Data/GridTemplate.aspx

Events and Commands

Events in c# and aspx

Event handlers

OnClick

http://iam.colum.edu/oop/classsource/class9/events/events1.aspx events1.aspx - source

OnCommand

http://iam.colum.edu/oop/classsource/class9/events/events2.aspx events2.aspx - source

http://iam.colum.edu/oop/classsource/class9/events/events3.aspx events3.aspx - source

<csharp>

<%@ Page language="c#" debug="True" trace="false"%>

<script language="c#" runat="server">

   Dog fido;
   
   public void Page_Load()
   {
       fido = new Dog();
       
       
   }
   public void Button1_OnClick(Object sender, EventArgs e)
   {
       Response.Write("Hello from Button1_OnClick");
       lblBark.Text = fido.Bark();
   }


   public class Dog 
   {
       public string Name;		// the dog's name
       public int Age;			// the dog's age
       public int Weight;			// the dog's weight
       public string BarkSound;	// the sound of the dog's bark
       public Dog()
       {
           BarkSound = "Woof!!!";
       }
       public string Bark()
       {
           return this.BarkSound;
       }
       public void Eat()
       {
           //put eat code here 
       }
   }	

</script>

Test

test
Hello in div

</csharp>


Create a new user account

To insert into a new user we need to to combine three steps.

  1. INSERT into the People Table
  2. Get the new PeopleID
  3. INSERT into the roles table

<sql> INSERT into People (salutationID, firstName, lastName, logonName, passwd) values (1, 'jeff', 'meyers', 'jmeyers', 'monkey') </sql>

Check the new users PeopleID

<sql> SELECT PeopleID from People WHERE firstName = 'jeff' and lastName='meyers' and logonName='jmeyers' </sql>

results PeopleID = 1

Give the new user a Role by inserting the PeopleID and a roleID into the roles table

<sql> INSERT into roles ( PeopleID, roleTypeID, RoleActive ) values ( 1, 1, 1) </sql>


Since all of these steps need to happen or fail as a complete unit we must use an transaction. Of course in .NET there are several way to accomplish this.

Test page one

http://iam.colum.edu/dd/classsource/class10/trans.aspx -source

Test page one with form

SQL transation

This can all be done in shorter statement by putting the Select query in the second INSERT

<sql> INSERT INTO People (salutationID, firstName, lastName, logonName, passwd) VALUES (1, 'jeffTest2', 'meyersTest2', 'jmeyersTest2', 'monkey')

GO

INSERT INTO roles ( PeopleID, roleTypeID, RoleActive ) ( SELECT PeopleID, 1, 1 FROM People WHERE firstName = 'jeffTest2' AND lastName='meyersTest2' AND logonName='jmeyersTest2' )

</sql>

By using the Keywords BEGIN TRANSACTION and COMMIT TRANSACTION we can ensure that our batched statements run as a transaction <sql> BEGIN TRANSACTION

/* Remove old trancation test so we can run it again */ DELETE from Roles where PeopleID in (SELECT PeopleID FROM People WHERE firstName = 'jeffTest2' AND lastName='meyersTest2' AND logonName='jmeyersTest2')

DELETE from People where firstName = 'jeffTest2' AND lastName='meyersTest2' AND logonName='jmeyersTest2'

GO

/*INSERT for tranaction */ INSERT INTO People (salutationID, firstName, lastName, logonName, passwd) VALUES (1, 'jeffTest2', 'meyersTest2', 'jmeyersTest2', 'monkey')

GO

INSERT INTO roles ( PeopleID, roleTypeID, RoleActive ) ( SELECT PeopleID, 1, 1 FROM People WHERE firstName = 'jeffTest2' AND lastName='meyersTest2' AND logonName='jmeyersTest2' )

COMMIT TRANSACTION </sql>

Stored Procedures

Stored procedures are a way in MSSQL to store a compiled SQL statement. The statement will run faster than a regular SQL statement because the execution plan has already been calculated. The plan is executed with a new set of parameters. There are both input parameters and output parameters. SQL parameters are prefixed with the @ sign.

Default Template

<sql> -- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> -- Add the parameters for the stored procedure here <@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, <@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0> AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;

   -- Insert statements for procedure here

SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2> END GO </sql>

Stored Procedure (SProc) to INSERT into people

<sql> -- ============================================= -- Author: Jeff -- Create date: -- Description: -- ============================================= CREATE PROCEDURE PeopleInsert -- Add the parameters for the stored procedure here @salutationID int = 1, @firstName varchar(50), @lastName varchar(50), @logonName varchar(50),

   @passwd varchar(50)

AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. -- SET NOCOUNT ON;

   -- Insert statements for procedure here

INSERT INTO People (salutationID, firstName, lastName, logonName, passwd) VALUES (@salutationID, @firstName, @lastName, @logonName, @passwd) END GO </sql>

You can test the stored procedure by running it and passing in all the required parameters.

<sql> PeopleInsert

@salutationID = 1, @firstName ='sprocTestFname', @lastName='sprocTestLname', @logonName ='sprocTestLogonName',

       @passwd ='monkey'

</sql>

all one line is fine

<sql> PeopleInsert @salutationID = 1, @firstName ='sprocTestFname', @lastName='sprocTestLname', @logonName ='sprocTestLogonName', @passwd ='monkey' </sql>


GetPeopleID <sql> CREATE PROCEDURE GetPeopleID -- Add the parameters for the stored procedure here @firstName varchar(50), @lastName varchar(50),

       @logonName varchar(50) 

AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;

       -- Insert statements for procedure here

SELECT PeopleID FROM People WHERE firstName = @firstName AND lastName= @lastName AND logonName= @logonName END </sql>

Again we can run it like this <sql> GetPeopleID @firstName ='sprocTestFname', @lastName='sprocTestLname', @logonName ='sprocTestLogonName' </sql>

Transactions

Whenever you are making changes (insert/update/delete) two more than one table or the results of a select statement are used to update another table you need to use a transaction. Transaction either succeed to fail as a complete unit. Trans actions can cause a lock on a row or tables and should be kept a brief as possible. After all of the work of the transaction is complete it can either be committed or rolled back.

Commit

Actually commits tht changes

Rollback

rolls back all changes and the database.

Transaction can also have scope.

Single SQL SProc

full InsertPersonAndRole

<sql> -- ============================================= -- Author: jeff -- Create date: -- Description: -- ============================================= CREATE PROCEDURE AddUserAndRole -- Add the parameters for the stored procedure here @salutationID int = 1, @firstName varchar(50) , @lastName varchar(50), @logonName varchar(50), @passwd varchar(50), @roleTypeID int AS BEGIN --Start transaction BEGIN TRANSACTION


--INSERT into People INSERT into People (salutationID, firstName, lastName, logonName, passwd) values (@salutationID, @firstName, @lastName, @logonName, @passwd)

--Get PeopleID DECLARE @PeopleID int

Select @PeopleID = @@identity

--INSERT into Roles INSERT into roles (PeopleID, RoleTypeID, RoleActive) values (@PeopleID, @roleTypeID, 1)

--Commit Transaction ROLLBACK TRANSACTION

       --COMMIT TRANSACTION

END GO

</sql>

and the SQL statement to call the stored procedure

<sql> AddUserAndRole @salutationID = 1, @firstName = 'fnTransTest' , @lastName ='lnTransTest', @logonName ='lnTransTest', @passwd ='pwTransTest', @roleTypeID = 1 </sql>

Stored Procedures

Add edit example this will add or edit if the record exsits already

<sql> -- ============================================= -- Author: Jeff Meyers -- Create date: -- Description: -- ============================================= ALTER PROCEDURE [dbo].[AddUpdatePerson] -- Add the parameters for the stored procedure here @UserName varchar(50), @OasisID varchar(50), @OasisEmail varchar(50), @Email varchar(50), @FirstName varchar(50), @LastName varchar(50), @PhoneNumber varchar(50) AS BEGIN DECLARE @PeopleID int

   -- Insert statements for procedure here

SELECT @PeopleID = PeopleID from People WHERE UserName = @UserName

IF @PeopleID is null BEGIN INSERT into People (UserName, OasisID, OasisEmail, Email, FirstName, LastName, PhoneNumber) VALUES (@UserName, @OasisID, @OasisEmail, @Email, @FirstName, @LastName, @PhoneNumber)

select @@identity as PeopleID END ELSE BEGIN UPDATE People set UserName = @UserName, OasisID = @OasisID, OasisEmail = @OasisEmail , Email = @Email , FirstName = @FirstName , LastName = @LastName, PhoneNumber = @PhoneNumber, LastUpdate = GETDATE() WHERE PeopleID = @PeopleID

select @PeopleID as PeopleID END END

</sql>

and now the ADO way

http://iam.colum.edu/dd/classsource/class10/trans.aspx - source

HomeWork

Try to create a use logon page that inserts a new user.

Sql Aggregate Functions

They perform a calculation on a set to values and return a single value. Aggregate functions are determinate. They will return the same value given the same dataset.

  • AVG
  • MIN
  • CHECKSUM
  • SUM
  • CHECKSUM_AGG
  • STDEV
  • COUNT
  • STDEVP
  • COUNT_BIG
  • VAR
  • GROUPING
  • VARP
  • MAX

<sql> SELECT MAX(PricePerPound) as MaxPrice from CheesePrice

SELECT AVG(PricePerPound) as AvgPrice from CheesePrice

SELECT COUNT(CheeseID) as Count from CheesePrice </sql>

Sub Query

A query may be a part of another query. This allows

IN vs EXSISTS

Remember the Many to Many relation ship in the Student Registration System

ManyToManyStudentCourses.png

Here a student has many course and a course has many student. Imagine in the registration system the student will be presented with a list of classes that they can add. That list of classes should not include the courses that they are already taking. Course

CourseID CourseName CourseNumber
9 Science 66-0002
10 Math 66-0001
11 Data Design 36-2601
168 Application Design 36-4601
169 OOP 36-2001

Student

StudentID PeopleID OasisID
1 1 666666
2 2 777777


StudentCourses

StudentID CourseID SemesterID
1 9 1
2 9 1
1 10 1

StudentsCourses_vw <sql> SELECT dbo.Student.PeopleID, dbo.Student.OasisID, dbo.StudentCourses.SemesterID, dbo.Course.CourseName,

 dbo.Course.CourseNumber, dbo.Student.StudentID, 
 dbo.Course.CourseID

FROM dbo.StudentCourses INNER JOIN

 dbo.Student ON dbo.StudentCourses.StudentID = dbo.Student.StudentID INNER JOIN
 dbo.Course ON dbo.StudentCourses.CourseID = dbo.Course.CourseID

</sql>

StudentsCourses vw.png

<sql> SELECT CourseID, CourseName, CourseNumber FROM Course WHERE (

  CourseID not in 
  (
     SELECT CourseID FROM StudentsCourses_vw WHERE StudentID = @StudentID
  )

) </sql>

This query has two parts

SELECT CourseID FROM StudentsCourses_vw WHERE StudentID = 1

returns

CourseID
9
10

then

<sql> SELECT CourseID, CourseName, CourseNumber FROM Course WHERE (

  CourseID NOT IN 
  (
     SELECT CourseID FROM StudentsCourses_vw WHERE StudentID = 1
  )

) </sql>

returns

CourseID CousreName CourseNumber
11 Data Design 36-2601
168 Application Design 36-4601
169 OOP 36-2001

Course adder example

http://iam.colum.edu/dd/classsource/class8/student.aspx

SQL Subquery

Email

Send Mail

<csharp><% @Page Language="C#" %> <% @Import Namespace="System.Web.Mail" %> <%

   //set up some strings for the email
   
   string strTo = "only_a_test@fastmail.fm";
   string strFrom = "jeff@interactive.colum.edu";
   string strSubject = "Hi jeff";
   string strBody = "A real nice body text here";
   
   //Send email
   SmtpMail.SmtpServer = "localhost";
   SmtpMail.Send(strFrom, strTo, strSubject, strBody);

%></csharp> http://iam.colum.edu/oop/classsource/class14/mail.aspx [-source]

C:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe

HomeWork

Final Proposal

Final Website proposal. Due 11/29. Final Proposal

Write a short requirements document (website) that explains

  1. Rationale: for website design or introduction of product features
  2. Audience: Description of target audience and segments for new website areas
  3. Requirements Summary: Key Areas and Features elaborate on requirements above
  4. Design Documents: Site Map (hand drawn, word doc, xml visio, paper napkin) and Data Diagram (sql 2008 diagram screen shot)

Final Requirements

The final website should show off all of your new .NET skills. I'll leave the idea and the content of the website up to you. Good proposals might be... An anonymous cheese rating website (similar) to midterm but using SQL server as the persistence layer. It would allow ratings for cheese from varios regions then show the most popular cheese by region.

  • Use Web Forms for user interaction
  • Use State (sessions, application, viewstate)
  • Use Database (I can help you design your db if you can't do this) with either SQLDataSource Direct ADO or LINQDataSource

Sample Cheese Poposal

Boyce-Codd Normal form

  • needs to be in 3NF

http://en.wikipedia.org/wiki/Boyce-Codd_normal_form

Fourth Normal Form

  • needs to be in BCNF

Fourth Normal Form

separates independent multi-valued facts stored in one table into separate tables.

http://en.wikipedia.org/wiki/Fourth_normal_form

Fifth Normal Form

  • needs to be in 4NF

Fifth Normal Form

breaks out data redundancy that is not covered by any of the previous normal forms.

http://en.wikipedia.org/wiki/Fifth_normal_form

More normal forms

http://en.wikipedia.org/wiki/Database_normalization

Mappath

Server.Mappath

upload permissions

Upload a File

http uploader

Add executionTimeout and maxRequestLength to the web.config so that large uploads will not fail.

<xml> <configuration>

   <system.web>
       <httpRuntime
           executionTimeout="1200"
           maxRequestLength="65536"
       />
   </system.web>

</configuration> </xml>

multipart form <csharp> <form enctype="multipart/form-data" runat="server"> <tr>

 <td>Select file to upload:</td>
 <td>
 <input id="myfile" type="file" runat="server"></td>

</tr> <tr>

 <td>
 <input type=button id="btnUploadTheFile" value="Upload" 
       OnServerClick="btnUploadTheFile_Click" runat="server" />
 </td>

</tr> </form> </csharp>

Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property

<csharp> void btnUploadTheFile_Click(object Source, EventArgs evArgs) {

   //Path to save file
   string strBaseLocation = "";
   
   if (null != myfile.PostedFile) 
   {
       // Get the HTTP posted file instance (to simplify the code) 
       HttpPostedFile postedfile = myfile.PostedFile; 
       
       // Get the filename 
       string filename = new System.IO.FileInfo(postedfile.FileName).Name; 
       string filesize = postedfile.ContentLength.ToString();
       try 
       {
           myfile.PostedFile.SaveAs(strBaseLocation+filename);
           txtOutput.InnerHtml = "File " + strBaseLocation + filename + " uploaded successfully";
       }
       catch (Exception e) 
       {
               txtOutput.InnerHtml = "Error saving " + strBaseLocation + filename + "

"+ e.ToString();

       }
       
       //Do some other stuff 
       //maybe  like send an email to let admin know file was uploaded
   }

} </csharp>

http://iam.colum.edu/oop/classsource/class14/up.aspx [up.aspx - source] [web.config - source]

Modifications

Uniqie filename

<csharp> // Get the filename

       string filename = new System.IO.FileInfo(postedfile.FileName).Name; 
       string strUniqueDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Ticks.ToString()  ;
       filename =  strUniqueDate + "_" + filename;

</csharp>

Add to database instead of sending email

Aspx Templates and Reuse

The template page

http://iam.colum.edu/dd/classsource/class11/UserControls/TemplateNoControls.aspx - source

Include Files

<csharp>

This is the header
Main Column

Content Content Content</a> </td>

   </td>

</tr>

</td> </tr> </table> </csharp>

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class11/UserControls/incs/col1.aspx

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class11/UserControls/incs/col3.aspx

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class11/UserControls/incs/foot.aspx

User Controls

User Controls are user defined controls that are reusable. They have and event model similar to the page class. They have an isolated scope. The page class can send data to user controls via user defined atributes.

User Controls must be registered via a Register Directive (this can also be done via web.config for an entire site) <csharp> <%@ Register TagPrefix="DataDesign" TagName="Col1" Src="controls/col1.ascx" %> </csharp>

the control can then be used by adding the custom tag to the page <csharp> <DataDesign:Col1 id="ucCol1" runat="server" /> </csharp>

http://iam.colum.edu/dd/classsource/class11/UserControls/TemplateUserControls.aspx

Controls

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class11/UserControls/controls/col1.ascx

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class11/UserControls/controls/col3.ascx

http://iam.colum.edu/dd/gbrowser.php?file=/classsource/class11/UserControls/controls/foot.ascx


Mail

<csharp> string strTo = "jmeyers3@iit.edu";

       string strFrom = "jmeyers3@iit.edu";
       string strSubject = "Hi jeff";
       string strBody = "A real nice body text here";

       
       //Send email
       //SmtpMail.SmtpServer = "mail2.iit.edu";
       //SmtpMail.Send(strFrom, strTo, strSubject, strBody);

       SmtpClient client = new SmtpClient("localhost", 25);
       client.DeliveryMethod = SmtpDeliveryMethod.Network;
       client.Send(strFrom, strTo, strSubject, strBody);

</csharp>

in web config <xml> <system.net> <mailSettings> <smtp deliveryMethod="Network" from="jeff@iam.colum.edu"> <network host="localhost" port="25" defaultCredentials="true"/> </smtp> </mailSettings> </system.net> </xml>

HomeWork

Final Proposal

Final Website proposal. Due 11/29. Final Proposal

Write a short requirements document (website) that explains

  1. Rationale: for website design or introduction of product features
  2. Audience: Description of target audience and segments for new website areas
  3. Requirements Summary: Key Areas and Features elaborate on requirements above
  4. Design Documents: Site Map (hand drawn, word doc, xml visio, paper napkin) and Data Diagram (sql 2008 diagram screen shot)

Final Requirements

The final website should show off all of your new .NET skills. I'll leave the idea and the content of the website up to you. Good proposals might be... An anonymous cheese rating website (similar) to midterm but using SQL server as the persistence layer. It would allow ratings for cheese from varios regions then show the most popular cheese by region.

  • Use Web Forms for user interaction
  • Use State (sessions, application, viewstate)
  • Use Database (I can help you design your db if you can't do this) with either SQLDataSource Direct ADO or LINQDataSource
Sample Cheese Poposal