Web Application designe, Assignments of Web Application Development

To show the related information of the products such as Image, Name, Price and display it on the webpage based on category.

Typology: Assignments

2020/2021

Uploaded on 06/16/2021

saleh-muataz
saleh-muataz 🇲🇾

4.3

(4)

9 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Tan Ming Ho CT050-3-2 WAPP TP046054
MODULE TITLE Web Application
MODULE CODE CT050-3-2-WAPP
INTAKE CODE UC2F1808CS
Table of Contents
1.0 Introduction..................................................................................................................................... 2
1.1 Objective...................................................................................................................................... 2
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Web Application designe and more Assignments Web Application Development in PDF only on Docsity!

MODULE TITLE Web Application

MODULE CODE CT050-3-2-WAPP

INTAKE CODE UC2F1808CS

Table of Contents

1.0 Introduction..................................................................................................................................... 2 1.1 Objective...................................................................................................................................... 2

1.0 Introduction

1.1 Objective

a) To develop a fully functional web application for customers to purchase fashion item conveniently. b) To show the related information of the products such as Image, Name, Price and display it

  • 1.2 Scope...........................................................................................................................................
  • 1.3 Project Schedule..........................................................................................................................
  • 2.0 Requirement Specification...............................................................................................................
    • 2.1 Audience Classification................................................................................................................
    • 2.2 Audience Characterization...........................................................................................................
  • 3.0 Design and Modeling.......................................................................................................................
    • 3.1 Data Schema................................................................................................................................
      • 3.1.1 Users.....................................................................................................................................
      • 3.1.2 Products................................................................................................................................
      • 3.1.3 Feedback...............................................................................................................................
    • 3.2 Interface Design...........................................................................................................................
      • 3.2.1 Storyboard............................................................................................................................
    • 3.3 Website Architectures.................................................................................................................
  • 4.0 Code Snippets (CRUD and Login).....................................................................................................
    • 4.1 Create..........................................................................................................................................
    • 4.2 Read.............................................................................................................................................
    • 4.3 Update.......................................................................................................................................
    • 4.4 Delete........................................................................................................................................
    • 4.5 Login
  • 5.0 Conclusion.....................................................................................................................................

2.0 Requirement Specification

2.1 Audience Classification

  1. Registered – Admin, User
  2. Non-Registered – Guest

2.2 Audience Characterization

  1. Admin a. Able to Login or Logout. b. Manage Admin Profile. c. Create new Admin Account. d. Manage Products.
  2. User a. Able to view products. b. Able to Login or Logout. c. Able to add product into cart and calculate total price.
  3. Guest a. Able to view products. b. Able to Login or Logout. c. Able to submit feedback.

3.0 Design and Modeling

3.1 Data Schema

3.1.1 Users Column Data Type Remarks UserID Int NOT NULL, Increment by 1 Name Varchar(50) NULL Email Varchar(50) NULL Username Varchar(50) NULL Password Nvarchar(50) NULL RPassword Nvarchar(50) NULL Usertype Varchar(10) NULL 3.1.2 Products Column Data Type Remarks ProductID Int NOT NULL, Increment by 1 ProductName Varchar(50) NULL

ProductDescription Varchar(MAX) NULL Category Varchar(50) NULL Price Decimal(18.2) NULL PImage Varchar(50) NULL 3.1.3 Feedback Column Data Type Remarks Id Int NOT NULL, Increment by 1 Name Varchar(MAX) NULL Email Varchar(50) NULL Feedback Varchar(MAX) NULL

3.2 Interface Design

3.2.1 Storyboard

3.3 Website Architectures

4.0 Code Snippets (CRUD and Login)

4.1 Create

protected void btnAdd_Click(object sender, EventArgs e)

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].Connection String); try { con.Open(); string fileName = FileUpload1.PostedFile.FileName; FileUpload1.SaveAs(Server.MapPath("Img/" + fileName)); string query1 = "Insert into Products (ProductName, ProductDescription, Category, Price, PImage) values (@pName,@pDesc,@pCate,@pPrice,@pImage)"; SqlCommand cmd1 = new SqlCommand(query1, con); cmd1.Parameters.AddWithValue("@pName", txtProdName.Text); cmd1.Parameters.AddWithValue("@pDesc", txtProdDesc.Text); cmd1.Parameters.AddWithValue("@pCate", txtProdCategory.Text); cmd1.Parameters.AddWithValue("@pPrice", txtProdPrice.Text); cmd1.Parameters.AddWithValue("@pImage", "Img/"+ fileName); cmd1.ExecuteNonQuery(); lblMessage.ForeColor = System.Drawing.Color.ForestGreen; lblMessage.Text = "Product Added Successfully."; con.Close(); } catch (Exception ex) { Response.Write("Error :" + ex.ToString()); } } The code snippet above implemented a Create/ an Insert function for Add.aspx , which is a Web Form that’s allows admin to add product into the Product Database. The admin is necessary to fill in all the textbox and click the ‘btnAdd; button to fire the event for insert at the front end, required textbox included:

SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].Connection String); con.Open(); string query = "select * from Products"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); string desc = reader.GetString(2); string cate = reader.GetString(3); decimal price = reader.GetDecimal(4); string img = reader.GetString(5); htmlStr += "" + id + "" + name + "" + desc + "" + cate + "" + price + "" + img + " <a class=boldblack href=EditProduct.aspx?id=" + id + ">Edit"; } con.Close(); return htmlStr; } The code snippet above implemented a Read/ a View function on ViewAll.aspx , which is a Web Form that will load the Products data from the database and display the data as a table. The code is stored in a string fetchData() which can be able to return the HTML Code to front-end. Initially, a htmlStr string variable is created to hold the html code that used to create the table. Similar to Insert function, SQL Connection has to be created. A SQL query used to select all data from the Products table is created and executed. SqlDataReader is an object used to sequentially read data from the database, and reader is declared as the variable for SqlDataReader. Then, a while loop is performed if the reader is still able to read data from the database, and several variables is declared to hold data which included:  name (Product Name)  desc (Product Description)

 cate (Product Category)  price (Product Price)  img (Product Image Path) htmlStr will be used to hold all these data that retrieved from the database, and combine as a command which can be able to create a table with data, it also included an Operation column with Edit button that will store the ProductID of the chosen Product and redirect the admin to the EditProduct.aspx. Con.Close() to close the Connection stream, and the htmlStr will be return to the fetchDat.

4.3 Update

protected void btnEdit_Click1(object sender, EventArgs e) { con.Open(); string fileName = FileUpload1.PostedFile.FileName; if (fileName = “”)

path which is Img. An if-else condtion is used to declare which type of edit should be execute, with image changing or without image changing. If the filename = “” condition is fulfilled, the SQL statement for updating product data without Image Changing will be created, the target data is based on the chosen ProductID which is retrieved from the ViewAll.aspx , then the cmd.ExecuteNonQuery() will execute the query and perform the update process. Else, if the else condition is fulfilled, meaning that the admin request to change the image, the uploaded image will be saved in the _Img_ path and the SQL statement with image changing will be created and executed. Con.close() is necessary to close the connection stream, and the admin will be redirect to the ViewAll.aspx.

4.4 Delete

protected void btnDelete_Click(object sender, EventArgs e) { con.Open(); string query = "delete from Products where ProductID = '"+id+"'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); con.Close();

The code snippet above implemented a delete function for EditProduct.aspx which is the same webform for the Edit function. The delete event will be triggered whenever the admin clicked the btnDelete button. The connection stream will be opened and a SQL Query used to delete Product Data based on the ProductID retrieved from EditProduct.aspx will be created and executed. Con.Close() close the connection stream.

4.5 Login

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].Connection String); con.Open(); SqlCommand cmd = new SqlCommand("select count(*) from Users where Username ='" + loginUsername.Text + "'and Password = '" + loginPassword.Text + "'", con);

5.0 Conclusion

Throughout this assignment, I have learnt how to create a functional website by using HTML, CSS, JS and ASP.NET Framework. In order to build a user-friendly interface, I tried to create the website with the help of Bootstrap, which caused me to save a lot of effort for designing, but also caused me to have trouble editing the design. I noticed that a website with bootstrap need to consume a lot of time and energy in order to understand the existing elements such as HTML, CSS and JavaScript, but fortunately I managed to edit the design based on my preference after much time. and efforts consumed. Database Connectivity allows me to gain more knowledge on how to connect a website to a database, which is necessary for a functional website to work instead of hard-coded website. In the future, I would like to develop a functional responsive website with WordPress, and also enhance my website coding skills and concept to develop a better website.